Hi
Although I have a background in programming, PERL is completely new to me...and I'm getting nowhere fast!! Hoping you can help!
I have obtained a PERL script that is used in conjunction with a web form to upload a customer's file (or files) to a server. The script is working perfectly except for one flaw...if the user's file does not exist locally (eg the user typed an invalid file name), the script still acts as though the file *was* uploaded successfully. In fact, it creates a zero-length file on the server, and reports to the user that the file was uploaded.
Ideally, I'd like the script to fail gracefully if the filename does not exist locally.
Can this be done???
The following is an extract of the script to give you some context. I have marked the area where I think (?) the appropriate test would go (assuming there is something that can be done).
$ERROR_BADFILE = "/ord_err1.htm";
$SAVE_DIRECTORY = "/home/usrname/www/orders"
;
...
$| = 1;
chop $SAVE_DIRECTORY if ($SAVE_DIRECTORY =~ /\/$/);
use CGI qw(:standard); # Script uses CGI.pm
$query = new CGI;
foreach $key (sort {$a <=> $b} $query->param()) {
next if ($key =~ /^\s*$/);
next if ($query->param($key) =~ /^\s*$/);
next if ($key !~ /^file-to-upload-(\d+)$/);
$Number = $1;
if ($query->param($key) =~ /([^\/\\]+)$/) {
$Filename = $1;
$Filename =~ s/^\.+//;
$File_Handle = $query->param($key);
#### --> Test in here? if ( ! (file exists locally)) {
#### redirect to error page (ie $ERROR_BADFILE)
#### then exit
} else {
print $query->redirect($ERROR_BA
DFILE);
exit;
}
Hoping someone can enlighten me!!
Thanks
David
Start Free Trial