Forum Moderators: coopster & phranque

Message Too Old, No Replies

File upload

the script does not work under linus/freebsd but is it ok under win.

         

itim

10:59 am on Apr 30, 2002 (gmt 0)



Questions on how to upload file to the server from web-page are so often that it is seems that everything is clear about it.

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/perl

print "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.

sugarkane

12:01 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to wmw itim

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!

itim

12:08 pm on Apr 30, 2002 (gmt 0)



Variables are defined correctly. I just deleted wrong line from the overcommented (due to plenty of tests) script.

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

sugarkane

12:29 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> nor DisableCharset On help.

It might just be a typo, but the Apache directive is (I think) CharsetDisable rather than DisableCharset.

Does that help?

itim

12:41 pm on Apr 30, 2002 (gmt 0)



I have never used that directive before and spelt it wrong first time, but I already replaced it.

"CharsetDisable On" now and no effect.

DrDoc

4:50 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried without binmode on *nix?

itim

11:27 am on May 1, 2002 (gmt 0)



Thanks to everyone who took part in the disscussion. The solution is simple. Adding CharsetRecodeMultipartForms Off
to .htaccess is enough.

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. ;-)