Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Corrupted Uploaded Images (JPG) 1

Status
Not open for further replies.

SimonMarkDawson

Programmer
Oct 17, 2001
23
GB
Dear All

I am having problems uploading jpg image files to my server (Using multi-part form transfer)

Although the file appears to have transferred as required (And the file size of the copy matches that of the original) the resultant uploaded image has been corrupted and is not displayed properly. The same result occurs whether I upload the data in several sequential chunks or all at once.

What is the problem and more to the point, can it be overcome?!

Thanks in advance etc.
 
How are you uploading the images? What do you do with them after they're uploaded? Do you copy them to another location from the temp upload file? We need more information to be able to help here. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks for the reply Tracy

My problem I think is that the data is being transferred as ascii type rather than data.

I am using the following form line in my HTML

<form method=&quot;post&quot; ENCTYPE=&quot;multipart/form-data&quot; action=&quot;upload.cgi&quot; name=&quot;form1&quot;>

and the following to read data in the upload.cgi script

while ($bytesread=read($fileID,$buffer,1024)) {
...
}

The file created is the same length as the original HTML yet the image is corrupt which makes me think the transfer type may be to blame. The files to be transferred are images (Mostly jpg)


Any idea why this might be and isn't there a dedicated binary read function in PERL?

Thanks again for your help.

- Simon
 
Are you setting binmode on the file handles you're read and writing? Under unix that shouldn't make a difference, but it might. Try:
Code:
binmode FILEHANDLE;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Tracy ... Hopefully you'll read this before wasting ages on the above as I've just solved the problem (Not sure how to remove a submission being new here - Prob a sep & lengthy thread in its own right!)

My problem was indeed one of ascii rather than binary transfer and the solution was as simple as including

binmode FILEHANDLE;

in the upload script where FILEHANDLE is that of the newly created file.

Thanks again for the help.

- Simon
 
Simon, apparently you figured it out and submitted your response just as I was submitting mine. Looks like you found the solution I suggested. Good job!
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
We must have been typing at the same time me thinks (That'll teach me to &quot;meddle with dragons&quot;)

Many thanks & good night.

- Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top