S
slugger3113
I have a CGI script that allows users to upload image files to a
website. I limit the file size to 75K.
The problem is if someone tries to upload a file larger than 75K, and
the user clicks Submit, the script basically just resets itself with
no warning; none of the functions get triggered.
Can someone tell me how to capture that "event" when a file size is
larger than 75K, and allow me to display a proper error message ("File
too big...")?
Here's what I've got, which successfully uploads the file if it's 75K
or lower, but doesn't display an error message if it's bigger:
my($imageFileMaxSize) = 75000;
$CGI:OST_MAX = $imageFileMaxSize;
# other stuff defining image name, path, etc.
sub create_new_image_file {
my $newImageFile = @_;
$file = param('imagefile');
open (SAVE, ">$newImageFilenamePath") || on_error("Can't save $file
to $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 for any advice!
Scott
website. I limit the file size to 75K.
The problem is if someone tries to upload a file larger than 75K, and
the user clicks Submit, the script basically just resets itself with
no warning; none of the functions get triggered.
Can someone tell me how to capture that "event" when a file size is
larger than 75K, and allow me to display a proper error message ("File
too big...")?
Here's what I've got, which successfully uploads the file if it's 75K
or lower, but doesn't display an error message if it's bigger:
my($imageFileMaxSize) = 75000;
$CGI:OST_MAX = $imageFileMaxSize;
# other stuff defining image name, path, etc.
sub create_new_image_file {
my $newImageFile = @_;
$file = param('imagefile');
open (SAVE, ">$newImageFilenamePath") || on_error("Can't save $file
to $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 for any advice!
Scott