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
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
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 :^)