Need help with a Perl Script Error

D

Darren Clark

I'm fairly new to writing Perl CGI Scripts. The script I've written
uploads a file to a web server. The script runs fine when I am using
IE from a windows machine, but when I use a MAC to call the script, I
get the following error message:

Undefined subroutine &main::Error called at
/home/comp/corp/ici1/www/scripts/upload.cgi line 28.
Program returned result 21. A value larger than 0 is an error.

The following is my script:

#!/bin/perl
# use strict;
use CGI ':standard';

#Define variables
$query = new CGI;


my $name= $query->param('u_file');
my $workorder= $query->param('work_order');
my $info= uploadInfo ($name);
my $type = $info -> {'Content-Type'};

$mypath = '../upload/'.$workorder;

#Create upload directory
# mkdir ($mypath, 0777);

#Strip directory structure
$name=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the
filename
my $newname = $2;

# Concatenate the path & file name for UPLOAD
$myupload = '>'.$mypath.'/'.$newname;


if ($name) {
open (UPLOAD, $myupload) || Error ();

my ($data, $chunk);
while ($chunk = read ($name, $data, 1024)) {
print UPLOAD $data;
}
close (UPLOAD);


}

I assume it has something to do with how a MAC passess the file
information that is being uploaded but am not sure if I am right or if
I am how to correct it. I've scoured the web and have come up with
nothing.

I'd appreciate it if someone could give me some direction.

Please reply to darren.clark@{no spam}clarkcompservice.com

Thank you,

Darren
 
S

Sherm Pendley

Darren said:
The following is my script:

#!/bin/perl
# use strict;

The error is above, on line 2. You've mistakenly commented out an important
piece of code.

sherm--
 
G

Gary E. Ansok

I'm fairly new to writing Perl CGI Scripts. The script I've written
uploads a file to a web server. The script runs fine when I am using
IE from a windows machine, but when I use a MAC to call the script, I
get the following error message:

Undefined subroutine &main::Error called at
/home/comp/corp/ici1/www/scripts/upload.cgi line 28.
Program returned result 21. A value larger than 0 is an error.

The following is my script:

#!/bin/perl
# use strict;
use CGI ':standard';

#Define variables
$query = new CGI;


my $name= $query->param('u_file');
my $workorder= $query->param('work_order');
my $info= uploadInfo ($name);
my $type = $info -> {'Content-Type'};

$mypath = '../upload/'.$workorder;

#Create upload directory
# mkdir ($mypath, 0777);

#Strip directory structure
$name=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the
filename
my $newname = $2;

# Concatenate the path & file name for UPLOAD
$myupload = '>'.$mypath.'/'.$newname;


if ($name) {
open (UPLOAD, $myupload) || Error ();

my ($data, $chunk);
while ($chunk = read ($name, $data, 1024)) {
print UPLOAD $data;
}
close (UPLOAD);


}

I assume it has something to do with how a MAC passess the file
information that is being uploaded but am not sure if I am right or if
I am how to correct it. I've scoured the web and have come up with
nothing.

Since the only call to Error() is when the open fails, I suppose
that is what is resulting in the error message.

What do the various variables contain when the error occurs?
Particularly $myupload and the parameters that are used to construct it.

What is in the Perl variable $! when the error occurs? This might
give you a clue as to _why_ the open fails.

Since $mypath appears to start with '../', what is the current directory?
Do you have the proper permissions to create $myupload?

Why do you have 'use strict' commented out?

Why do you call a function called Error() and not define it?

What happens if $name does not contain a '/' or a '\\'?

It is quite possible that something in the way the upload is passed in
is causing $myupload to not be a valid filename on your system. If
you were to print out the contents of $myupload, you would probably
be able to tell whether that is the case and what you might be able
to do about it.

Gary Ansok
 
J

Joe Smith

Darren said:
#Strip directory structure
$name=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename
my $newname = $2;

You are blindly using $2 without bothering to check if m// succeeded. That
is guarenteed to fail for $name="My G5:Main directory:Subdir:File Name".

At bare minimum, change that to
my $newname = $name =~ s/.*[/:\\]//;
or "use File::Spec;" to split off the directory part.
-Joe
 

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
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top