Reputation: 104
I want to display an image using this php script on my server.
$file = fopen('/Volumes/PROMISE/products/jpeg/89239-282.jpg', 'rb');
header('Content-Type: image/jpeg');
fpassthru($file);
But i get an broken image, this script is at the top of my index file, right now for testing purposes, so i dont think theres an headers issue, infact its the only thing in my index file...
I've tried using
echo file_get_contents('/Volumes/PROMISE/products/jpeg/89239-282.jpg');
aswell, without any luck, the file exists at the specified path and it has 777 permission.
My last thoughts is that it might be some config on the apache server..? Dont know if theres even a setting that can brake the images?
This is the .htaccess file settings
Options +FollowSymlinks -Multiviews
This is the config from the httpd.conf file
Options All -MultiViews -ExecCGI -Indexes
I checked the mime.types file and the image/jpeg is active.
So i guess my question is: Is there some possibility the apache setup is messing with my images.
edit:
i tried using the code from php man
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($im);
// Free up memory
imagedestroy($im);
On my local computer it works, but not on our server. It gets me a blank page and no errors.
If i use imagejpeg with the second param and saves it to the desktop, it seems to be all fine and fully viewable
Upvotes: 0
Views: 2078
Reputation: 14681
I have seen that issue many times. If you haven't done so, try opening the broken image with a text editor to see if there is something wrong about it. Try a diff between the resulting file and the original file (from the server).
Possible errors that come to mind: PHP notices or warnings displaying in your image, blank characters. For example, an empty line before the opening might break your image.
Upvotes: 1