PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$data = "";
//Get the file
//TODO: I would look up the iid in the db instead of a static thing...
$file = "somepicture.jpg";
$fp = fopen("images/".$file, "rb");
header("Content-Type: image/jpeg\n");
header("Content-Transfer-Encoding: binary\n");
header("Content-length: " . filesize("images/".$file) . "\n");
fpassthru($fp);
fclose($fp);
?>
When I run it, it gives me the broken-picture thingy. Can anyone see anything that I am doing wrong? can you try it out on other browsers, maybe (<img src="displayImage.php"> or similar)?
Code works fine. Nothing wrong with it...check your filename, image, etc.
Second two header lines are not needed.
Image type might be wrong. Just cause it has a jpg extension doesn't make it one. Might try a conditional that checks the return values from getimagesize() and then delivers back the appropriate header() command.
Well, I checked the jpg. At first it was a photoshop jpg, so I thought maybe the extra info that photoshop puts in could screw it up, so I used a picture I found on google. Still same problem. Then I tried just calling the script, not inside an image tag, and it wouldn't open it. It's like apache didn't pass it on to the php interpreter.
Update: I got that figured out. Now I still get the broken image, but if I just go to the script, then it downloads the picture, perfectly readable, etc. The browser just won't open it. I have tried it with the same results on multiple browsers...
Are you sure your file is something.jpg and not something.JPG ? Adobe sometimes changes the extention. Correct me if I'm woring but your system might be case sensitive.
One more question:
What size is the broken image? Is the same as the original image?
I checked the filename, and everything. It's all correct. And the broken image is as small as the broken-image icon can get and still be a full icon. Does that make sense? It is smaller than the actualy image