• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

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;
      }
0
troyd1
Asked:
troyd1
  • 3
  • 2
1 Solution
 
rugdogCommented:
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?
0
 
ozoCommented:
for( $uploadfile,$church ){
   s/([% #&])/sprintf("%%%02X",ord($1))/eg;
}
print "window.location=\"http://www.mywebsite.net/cgi-bin/mywebsite.exe/PGM?SUBMIT=FileUploaded&Filename=$uploadfile&Church=$church\";}";
0
 
rugdogCommented:
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\";}";
 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
troyd1Author Commented:
I am using iis with windows 2000 advanced server. It creates a file in the upload directory with 0 bytes.
0
 
rugdogCommented:
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.
0
 
troyd1Author Commented:
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">
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now