Page 1 of 1

Need help with (supposidly) simple code

Posted: Thu Jan 15, 2004 3:48 pm
by FancyPants
Hi all,

I have some code here:

Code: Select all

<?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)?

Thank you for any help you can give,
Me.

Posted: Thu Jan 15, 2004 4:00 pm
by Dr Evil
I've just tested it. It seems to work fine with me. Are you opening the right image filename? Is the extention of your file JPG or jpg ???

Dr Evil

Posted: Thu Jan 15, 2004 6:47 pm
by uberpolak
Are you sure the file isn't corrupt? The image file that is?

Posted: Thu Jan 15, 2004 9:03 pm
by ilovetoast
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.

peace

Posted: Fri Jan 16, 2004 11:38 am
by FancyPants
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...

Thanx everyone,
Me

Posted: Fri Jan 16, 2004 1:32 pm
by Dr Evil
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?

DR Evil

Posted: Fri Jan 16, 2004 1:40 pm
by FancyPants
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