When I hade to make sucj script, I found that its behaviour is very strange.
I simplified the script to minimum, excluding extra features.
HTML-form is like this:
<html>
<body>
<form method=POST action=/cgi-bin/upload.pl enctype=multipart/form-data>
<input type=file name=filename><br>
<input type=submit>
</form>
</body>
</html>
The simplified CGI Perl script is this:
#!/usr/bin/perlprint "Content-Type: text/html\n\n";
use CGI;
my $cgi = new CGI;
my $filename = $cgi->param ('filename');
my $filetosave = "/home/WWW/file.gif";
#my $fh = $cgi->upload ($filename);
my $buffer = "";
open OUT, ">$filetosave";
binmode $fh;
binmode OUT;
while (read $filename, $buffer, 16384){
print OUT $buffer;
}
close OUT;
When this script is run under Windows+Apache on my local machine, it works. But as far as it is run on the server, if fails. File "file.gif" appeares in the desired place, its size is correct but the contents is wrong.
When I tried to use another construction
my $fh = $cgi->upload ($filename);
...
while (read $fh...){
...
the script stops at the line with upload() call.
It certainly sounds as if it's a platform issue, as handling of binary data is one of the big differences between *nix and windows.
In the code you've given, you use 'binmode $fh' but you haven't defined $fh - maybe changing to 'binmode $filename' will fix things? Let us know how you get on!
"binmode" are applied to any file I work with.
Meanwhile I found that any occurence of 0x00 is replaced with space code (0x20). It is said in RU-net that this is a trouble of Russian version of *nix Apache.
Neither CharsetRecodeMultipartForms Off
nor DisableCharset On help.
I still have not found the solution...
"CharsetDisable On" now and no effect.
So long way to it was because of my inattention: I placed that directive into .htaccess file located in WWW directory instead of cgi-bin one. ;-)