Page 1 of 1

PHP File Upload Question

Posted: Thu Nov 17, 2005 2:45 pm
by Plague
My idea was to have a single upload form that posts to the same page, so that a user could upload as many images as they wanted. As a file is uploaded, it is processed and a thumbnail of it appears in a list with all the other pictures, complete with options and such.

Only problem is, when I upload an image, the image gets printed (not as an image, but the gibberish seen when opening the file in notepad) on the top of the page. I've searched on google for a while and I have yet to find how to fix it.

I'm running (local server on Windows XP Pro x64):
Apache 2
PHP 5

Any suggestions?

Posted: Thu Nov 17, 2005 3:01 pm
by DCrazy
In the php file that displays an image, you need to do a header('Content-Type: image/gif'); or image/jpeg or whatever is appropriate before outputting the contents of the image.

You can't just output the data from a bunch of images into an HTML file. You need to output something like <img src="get_thumbnail.php?picture=001"> and then get_thumbnail.php is responsible for outputting the content-type header and fpassthru-ing (or however else you want to do it) the image.

Posted: Thu Nov 17, 2005 3:28 pm
by Plague
That's not it. I output the file when I want to just fine. Its that when the user uploads the file, it is displayed as text at the top of the page. Its not in my code intentionally. I was thinking that it might be an option somewhere that should be turned off.

Posted: Thu Nov 17, 2005 5:16 pm
by DCrazy
What's the code for your upload script(s) look like? Sounds to me like something's being unintentionally file()'d or fpassthru()'d.

Posted: Thu Nov 17, 2005 6:26 pm
by Plague
I found the problem. The code I had to generate thumbnails was not specifying the second parameter for the imagejpeg function, so it was writing the output stream to the page.