PHP File Upload Question

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
Plague
DBB Ace
DBB Ace
Posts: 315
Joined: Thu Jul 26, 2001 2:01 am

PHP File Upload Question

Post 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?
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post 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.
User avatar
Plague
DBB Ace
DBB Ace
Posts: 315
Joined: Thu Jul 26, 2001 2:01 am

Post 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.
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post 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.
User avatar
Plague
DBB Ace
DBB Ace
Posts: 315
Joined: Thu Jul 26, 2001 2:01 am

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