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;
      }
troyd1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.