Reputation: 85
How can I get this to provide an actual image?
file_put_contents($url,$image);
The size, and name are posted to directory correctly, but the image appears broken. Do I need to encode, or decode?
Just to inform you, $image comes from the following:
ob_start();
echo imagejpeg($image,null,30);
$image = ob_get_clean();
ob_end_clean();
$image = addslashes($image);
$image has successfully been posted to mysql as is, but I have been struggling to get it into directory.
Upvotes: 2
Views: 1499
Reputation:
imagejpeg()
outputs the image to the output buffer. You're using echo imagepeg()
which will output the image then immediately echo the true/false
return value of your function call.
Further, you're corrupting your image by doing this: $image = addslashes($image);
, which I imagine is done for the benefit of your database.
What you need is
ob_start();
imagejpeg($image,null,30);
$image = ob_get_clean();
file_put_contents($url,$image);
I don't see why you're storing the image in the database and in the file system. The filesystem should be good enough: store the path & file name in the database.
If you feel you must add the image to the database don't use addslashes()
but escape it with the function provided by the API you're using, at the point you want to execute the query. You'd be better using prepared statements so that escaping the data is unnecessary.
Upvotes: 1