Prbolem Showing Images

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm a bit new to PHP and am having trouble with displaying an image through
ANY of the IMAGE commands.

I've read EVERY tutorial I could find, and even copied the code from
exmaples...and nothing runs.

I am running PHP version 4 (4.4.6) with GD 2.0

Each and every image I attempt to display (either through striaght PHP or a
call through an IMG link) shows up as RAW-DATA text.

I am running on a LINUX serever with PHP 4.4.6

PHP info tells me that I have GD enabled with Jpeg and with PNG.

I've tried each and every type of image, several different images, and all I
get is
the following:

3PUTFQa"'V[UefwYyzg"WyR ?([b:?e:
aJ"SJ9 "$3+?==ZovY.4=<f"T^TMUTR)>9^
.?9li-RUSrZ  uȐ?xwnZ ?<<Y`js)Tԍ ^@ LtBѴ
YqSJlff^tQRJTw?myqP @D"vozG'! j  


Putting in the HEADER command nets:

Warning: Cannot modify header information - headers already sent by (output
started at /home/karstens/public_html/test/imgtest.php:9) in
/home/karstens/public_html/test/imgtest.php on line 11

and then the file output as raw data.

any suggestions?  Fixes?  Advice?

Re: Prbolem Showing Images

Gladen Blackshield wrote:

Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it


Well, the header is your problem.
You MUST set the right header before sending the imagedata. MUST.
So if you get that error, that means you have been sending other information  
first. It can be as much as a newline or a space.
Fix that first.

And one other thing: IF you set the headers right, you will NOT see this  
kind of messages anymore, because the browser expects an image.
A simple workaround is temporarely setting your header to text/html, check  
if any errors are produced, fix them, then set beack to image/png.

Good luck.

Erwin Moller

Re: Prbolem Showing Images

Quoted text here. Click to load it

Yes, the header() should come _before_ any other output. You output  
something on line 9 (or before). Either this should not be outputted, or  
the header() function should be earlier in the script. Keep in mind that  
any whitespace/characters outside <?php ?> tags are considered output, so  
in this file:

$foo = 'bar';

//rest of code

Output will have started on line 4, so no header can be send.
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions:

Re: Problem Showing Images

Thanks everyone (and sorry about that multipost...long day & longer night)

You're right, it was a header problem.

For some reason, I thought that I should use imagecreatefromjpeg and  
imagejpeg for a JPG file...

And of course, the whole time the PNG header was right there in my face,  
everytime the image didn't didn't display properly.

Changing the header and commands to PNG instead of Jpeg fixed it all.

Quoted text here. Click to load it

Site Timeline