Link to home
Start Free TrialLog in
Avatar of troyd1
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\\".$uploadfile;
open (UPLOAD,">$bfile") || Error ();
binmode UPLOAD;
        my ($data, $length, $chunk);
      while ($chunk=sysread($file,$data,1024)) {
            print UPLOAD $data;
            }
      close (UPLOAD);      

$files=$files."\~".$uploadfile;
}
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;
      }
Avatar of rugdog
rugdog
Flag of Mexico image

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
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or

($uploadfile,$church)=map({CGI::escape($_)} ($uploadfile,$church));
print "window.location=\"http://www.mywebsite.net/cgi-bin/mywebsite.exe/PGM?SUBMIT=FileUploaded&Filename=$uploadfile&Church=$church\";}";
 
Avatar of troyd1
troyd1

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.
Avatar of troyd1

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-data">