Need help with (supposidly) simple code

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!

Moderator: General Moderators

Post Reply
FancyPants
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2004 3:48 pm
Location: Clearwater, FL

Need help with (supposidly) simple code

Post 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.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post 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
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

Are you sure the file isn't corrupt? The image file that is?
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post 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
FancyPants
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2004 3:48 pm
Location: Clearwater, FL

Post 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
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post 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
FancyPants
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2004 3:48 pm
Location: Clearwater, FL

Post 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
Post Reply