Advertisement

03.09.2004 at 04:25AM PST, ID: 20912237
[x]
Attachment Details

Determining if a file exists (PERL)

Asked by DavidLeeding in CGI Scripting

Tags: perl, file, exists

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_BADFILE);
        exit;
    }

Hoping someone can enlighten me!!

Thanks

DavidStart Free Trial
[+][-]03.09.2004 at 05:05AM PST, ID: 10549722

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.09.2004 at 12:36PM PST, ID: 10554354

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.09.2004 at 02:26PM PST, ID: 10555473

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.09.2004 at 04:08PM PST, ID: 10556244

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.09.2004 at 04:27PM PST, ID: 10556396

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.10.2004 at 07:03AM PST, ID: 10561199

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.11.2004 at 02:54AM PST, ID: 10569931

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.11.2004 at 02:57AM PST, ID: 10569954

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.11.2004 at 03:01AM PST, ID: 10569975

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.15.2004 at 02:50PM PST, ID: 10601867

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.15.2004 at 03:39PM PST, ID: 10602136

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.07.2004 at 09:55PM PDT, ID: 11256626

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: CGI Scripting
Tags: perl, file, exists
Sign Up Now!
Solution Provided By: Netminder
Participating Experts: 6
Solution Grade: B
 
 
[+][-]06.07.2004 at 09:55PM PDT, ID: 11256629

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32