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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Uploading .doc And .pdf Files

Status
Not open for further replies.

JamSnax

Programmer
Dec 5, 2002
3
0
0
US
I am using the html <INPUT Type=&quot;file&quot; name=&quot;document&quot;> tag to upload files via Perl to a directory.

Text and HTML files upload fine, but .doc and .pdf files somehow get corrupted. The file size is the same, but it will not open or opens but is blank.

The Perl for writing the file is:

open UPLOADFILE, &quot;> $base_dir/$file_name&quot; || die &quot;Couldn't open FH for output&quot;;
while ( <$upload_filehandle> ) {
print UPLOADFILE;
}

Does anyone know what might be happening? Is this a plain text vs binary data issue?

All feedback welcome!
 
try using binmode() on the filehandle after opening it:

open UPLOADFILE, &quot;> $base_dir/$file_name&quot; || die &quot;Couldn't open FH for output&quot;;
binmode (UPLOADFILE);
....

I guess you would have to do a check to determine if the file is binary or text, but i'm not sure how.
I do know that PDF files can be tricky because they don't always contain binary data although they technically are binary. I read somewhere that Adobe recommends adding binary data to a header in the pdf file or something when creating them so that other programs will treat them as binary files. I don't really think it's something you have to worry about though. I would just use binmode on any file with a .pdf extension.

Hope this helps somewhat.. I'm not an expert by any means. I'm sure someone else will be able to help you out more.
 
Thanks chazoid,

That worked great! I tested several files in each file type and was able to open them just fine.

You're more of an expert than you thought. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top