> -----Original Message----- > From: Quentin Smith [mailto:[EMAIL PROTECTED]] > Sent: 11 July 2002 20:07 > To: Tim Moore > Cc: [EMAIL PROTECTED] > Subject: Re: Uploading files > > > > I believe was is happening is this: > Each time you call read(), it fetches up to 1024 bytes (1kb, as you > set). Since each time read is called, it erases $PostedData and then > writes up to 1024 bytes into it, you can only end up with the > last 1024 > bytes. HOWEVER, the last time read is called, it reaches EOF, so the > last thing $PostedData is set to is undef. Here is a modified > version of > the code that I think will work (untested): > > my $length = $Request->{TotalBytes}; > print "TotalBytes = " . $length . "<br>"; > > my $fileup = $Request->{FileUpload}{uploadedfile}; > my $filehandle = $fileup->{FileHandle}; > my $PostedData = ""; > print "PostedData = " . $PostedData . "<br>"; > print "Length = " . length($PostedData) . "<br>"; > my $in_buffer; > while (read($filehandle, $in_buffer, 1024)) > { > print "a"; > $PostedData .= $in_buffer; # Equivalent to > $PostedData = > $PostedData . $in_buffer, except .= is shorter and faster. > # data from the uploaded file read into $PostedData > } > > my $ContentType = $fileup->{ContentType}; > print "ContentType = " . $ContentType . "<br>"; > > print "PostedData = " . $PostedData . "<br>"; > print "Length = " . length($PostedData) . "<br>"; > # As always, watch for line breaks. > > __END__ > > HTH, > --Quentin
Fantastic. That was the problem! I love it when the fix is so simple. It looks like I don't need CGI in the end but then I guess it's because my form is only posting the file so there's nothing to seperate? Seems to work anyway I can upload a PDF and return it and just tested it with BinaryWrite also and the PDF opens in Acrobat Reader! Cool. Many thanks :-) Tim. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
