troyd1
asked on
perl file uploading problem
I created this script that uploades a file. It works fine except it fails if there is a # in the file name. If the file name is "test.txt" it will upload fine, but if the file name is "test #test.txt" it does not work. Any ideas? Here is the code:
#!/perl/bin/perl.exe
use CGI ':standard';
print "Content-type: text/html\n\n";
print "<html><head>";
print "</head>";
print "<body>";
print "File uploading, please wait....";
print "</body>";
print "</html>";
$files="";
my $file=param('Filename');
my $church=param('Church');
my $upfile=$file;
$upfile=~ s/\\/\//g;
my @path=split(/\//,$upfile);
my $uploadfile= $path[$#path];
if ($file) {
my $bfile="c:\\TEMP\\UPLOAD\\ ".$uploadf ile;
open (UPLOAD,">$bfile") || Error ();
binmode UPLOAD;
my ($data, $length, $chunk);
while ($chunk=sysread($file,$dat a,1024)) {
print UPLOAD $data;
}
close (UPLOAD);
$files=$files."\~".$upload file;
}
print "<html><head>";
print "<script language=\"javascript\">";
print "function start() {";
print "window.location=\"http://www.mywebsite.net/cgi-bin/mywebsite.exe/PGM?SUBMIT=FileUploaded&Filename=$uploadfile&Church=$church\";}";
print "</script>";
print "</head>";
print "<body onload=\"start()\">";
print "</body>";
print "</html>";
sub Error {
print "Couldn't open temporary file: $!";
exit;
}
#!/perl/bin/perl.exe
use CGI ':standard';
print "Content-type: text/html\n\n";
print "<html><head>";
print "</head>";
print "<body>";
print "File uploading, please wait....";
print "</body>";
print "</html>";
$files="";
my $file=param('Filename');
my $church=param('Church');
my $upfile=$file;
$upfile=~ s/\\/\//g;
my @path=split(/\//,$upfile);
my $uploadfile= $path[$#path];
if ($file) {
my $bfile="c:\\TEMP\\UPLOAD\\
open (UPLOAD,">$bfile") || Error ();
binmode UPLOAD;
my ($data, $length, $chunk);
while ($chunk=sysread($file,$dat
print UPLOAD $data;
}
close (UPLOAD);
$files=$files."\~".$upload
}
print "<html><head>";
print "<script language=\"javascript\">";
print "function start() {";
print "window.location=\"http://www.mywebsite.net/cgi-bin/mywebsite.exe/PGM?SUBMIT=FileUploaded&Filename=$uploadfile&Church=$church\";}";
print "</script>";
print "</head>";
print "<body onload=\"start()\">";
print "</body>";
print "</html>";
sub Error {
print "Couldn't open temporary file: $!";
exit;
}
when you say that it doesn't work, how do you knwo that? I mean, for sure the file doesn't appear on the upload directory, but do you see any errors in the web server or in the client? which web server are you using? Also, can y ou post the HTML of the form used to upload the file?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or
($uploadfile,$church)=map( {CGI::esca pe($_)} ($uploadfile,$church));
print "window.location=\"http://www.mywebsite.net/cgi-bin/mywebsite.exe/PGM?SUBMIT=FileUploaded&Filename=$uploadfile&Church=$church\";}";
($uploadfile,$church)=map(
print "window.location=\"http://www.mywebsite.net/cgi-bin/mywebsite.exe/PGM?SUBMIT=FileUploaded&Filename=$uploadfile&Church=$church\";}";
ASKER
I am using iis with windows 2000 advanced server. It creates a file in the upload directory with 0 bytes.
so the 0 byte file does have the original filename with the "#" in it? have you tried ozo's suggestion?
Please post the "<form> " tag of the HTML form you use to upload the file.
Please post the "<form> " tag of the HTML form you use to upload the file.
ASKER
I have not had a chance to test. Here is the form tag info.
<form name=form2 method=post action="http://www.whatever.net/cgi-bin/default.pl" enctype="multipart/form-da ta">
<form name=form2 method=post action="http://www.whatever.net/cgi-bin/default.pl" enctype="multipart/form-da