strange behavior when using 'read'

S

sstark

Hi, I have a web/cgi script that allows users to upload a file to the
web server. I want to only allow files up to a certain size, which is
stored in $imageFileMaxSize (typically 75K). That part works correctly,
i.e. the script does not allow uploads larger than $imageFileMaxSize.

The problem is, when a user attempts to upload a file larger than
$imageFileMaxSize, the on_error routine is not called; instead the
script reloads from its starting point, with no message. My users find
this confusing, sometimes thinking the file has been uploaded,
sometimes getting frustrated and trying again.

How can I get on_error to display the proper message? Here's my code:

$imageFileMaxSize = 75000;
$CGI::pOST_MAX = $imageFileMaxSize;

sub create_new_image_file {
my $newImageFile = @_;

$file = param('imagefile');

open (SAVE, ">$newImageFilenamePath")");
while (read($file,$data,1024)) {
print SAVE $data;
$imageFileLength += length($data);
on_error("Image file is too large; maximum size allowed is
$imageFileMaxSize") if($imageFileLength > $imageFileMaxSize);
}
close(SAVE);
on_error("File was not received; check filename.") if($imageFileLength
< 1);

}

thanks!
Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top