Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help with Perl upload script

         

dcubed

1:36 am on Dec 22, 2002 (gmt 0)

10+ Year Member



My first post here & I'm very much a perl newbie. I've got a perl scripting problem I'd love some feedback on.

I have an HTML form with four fields that take text input, and one that allows users to browse to an image file to upload. It uses an SSI to edit another page that includes the uploaded info and - theoretically - the image. The script works - it updates the page, and if you look at the logs, source code, etc all the paths for the image file are correct. Except the image file is 0 bytes in size. I should mention I'm using Apache 2.0 as a test server and IE 5.0 as a client. Here's the sort & upload code :

#sort the form fields
foreach $key (sort { $a <=> $b }$query->param()) {

if ($key eq 'headline') {
$headline=$query->param('headline');
} elsif ($key eq 'date') {
$datesub=$query->param('date');
} elsif ($key eq 'story') {
$story=$query->param('story');
} elsif ($key eq 'photo') {
$origfile = $query->param('photo');
$origfilehandle = $query->param('photo');
} elsif ($key eq 'submit') {
#do nothing with submit
}
else{
&pout($value);
};
}

$BytesRead = 0;
undef $Buffer;

foreach($Bytes = read($origfilehandle,$Buffer,1024)) {
$BytesRead += $Bytes;
print OUTFILE $Buffer;
if ($BytesRead >2560000) {
close(OUTFILE);
&out("Error - image was too large, it was truncated ($BytesRead Bytes)");
# &exit();
};
}

What is particularly puzzling is that this code works in another script I'm running(as you can see - I'm a "cut-& paste programmer")but in this instance everything works, it just doesn't copy the image file.

I'm grateful for any thoughts

jatar_k

7:14 pm on Jan 6, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld dcubed, sorry no one responded to this.

Have you figured it out? Would one of the resident perl folk like to hazard an answer?

andreasfriedrich

8:17 pm on Jan 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using multipart/form-data encoding to upload the file as explained here?

HTML 4.01 - enctype attribute [w3.org]
CGI.pm - upload field [perldoc.com]

Are you running your script with warnings enabled? You should!

Have you tried using the upload function which is more secure and will work even while useŽing strict?

Andreas

dcubed

7:46 pm on Jan 9, 2003 (gmt 0)

10+ Year Member



Thanks for your help! The script has sort of slid to the back burner over the last week or so, but it's still not working. I am using multipart/form-data encoding and warnings are enabled.

I'll give the upload function a try & see what happens. What I find strange is that all of the form fields upload successfully with the exception of the "photo" field, which creates the target file but puts nothing in it.

I love challenges :^)