S
Suk
Hi
I'm tinkering with a simple file upload script
I want to be sure that if a user enters an invalid filename (i.e one
that doesnt exist) in a webform an error is returned. In the CGI
documentation it says the upload( ) method should return undef for an
invalid filehandle, but I cant seem to get this to work:
Here is the script im using:-
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI qwstandard);
our $upload_dir = "/tmp";
our $filename;
our $upload_filehandle;
our $message="Thank you";
$filename = param("file");
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = upload("file");
die "Invalid filehandle" if (!defined($upload_filehandle));
open UPLOADFILE, ">$upload_dir/$filename";
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
print header;
print <<END_HTML;
<HTML>
<HEAD>
<TITLE>Thank you for your upload</TITLE>
<script type="text/javascript">
alert("$message");
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
END_HTML
The "die" seems to be ignored, and I get an empty file in /tmp if I
enter a non-existent file in the webform?
I'm tinkering with a simple file upload script
I want to be sure that if a user enters an invalid filename (i.e one
that doesnt exist) in a webform an error is returned. In the CGI
documentation it says the upload( ) method should return undef for an
invalid filehandle, but I cant seem to get this to work:
Here is the script im using:-
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI qwstandard);
our $upload_dir = "/tmp";
our $filename;
our $upload_filehandle;
our $message="Thank you";
$filename = param("file");
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = upload("file");
die "Invalid filehandle" if (!defined($upload_filehandle));
open UPLOADFILE, ">$upload_dir/$filename";
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
print header;
print <<END_HTML;
<HTML>
<HEAD>
<TITLE>Thank you for your upload</TITLE>
<script type="text/javascript">
alert("$message");
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
END_HTML
The "die" seems to be ignored, and I get an empty file in /tmp if I
enter a non-existent file in the webform?