为什么我上传文件后,变成0字节了呢?

为什么我上传文件后,变成0字节了呢?

不太明白,请各位帮忙!
不知道哪里有问题,上传的文件都是0字节的

[Copy to clipboard] [ - ]
CODE:
#!/usr/bin/perl -w

print "content-type: text/html\n\n";
        use strict;
        use CGI qw(:standard);

print header;
print start_html(-title=>'test upload file');
print start_form(-method=>'POST',
                 -enctype=>"multipart/form-data",
                 -action=>'/awm/dd.pl');
print <<EOF;
        <input type="file" name="uploadfile">
EOF

##print start_multipart_form.filefield(-name=>'uploadfile');
print br.submit('submit','Send').end_form;
print end_html;

my $upload_dir = "/usr/local/aaa/uploadfile" ;
if(param()){
        my $q = new CGI;
        my $filename = $q->param('uploadfile');
        $filename =~ s/.*[\/\\](.*)/$1/;
        print $filename."<br>";
        open UPLOAD, ">$upload_dir/$filename";
        binmod UPLOAD;
        close UPLOAD;
}

看看权限设置是否正确吧
你都不读一下不写一下怎么把文件写进去啊
http://search.cpan.org/~lds/CGI.pm-3.29/CGI.pm
去掉binmode,然后加上写,如下:
while (my $bytesread = read($file, my $buffer, 1024)) {
                print OUTFILE $buffer;
        }

之前要加上my $file = $q->param('uploadfile');

可是如果是加binmode ,就是以二进制上传,会报IO:handle的错,需要怎么做?


QUOTE:
之前要加上my $file = $q->param('uploadfile');

你用的$file是一个字符串,但是

[Copy to clipboard] [ - ]
CODE:
However, there are problems with the dual nature of the upload fields. If you use strict, then Perl will complain when you try to use a string as a filehandle. You can get around this by placing the file reading code in a block containing the no strict pragma. More seriously, it is possible for the remote user to type garbage into the upload field, in which case what you get from param() is not a filehandle at all, but a string.

所以

[Copy to clipboard] [ - ]
CODE:
To be safe, use the upload() function (new in version 2.47). When called with the name of an upload field, upload() returns a filehandle, or undef if the parameter is not a valid filehandle.

     $fh = upload('uploaded_file');
     while (<$fh>) {
           print;
     }

用upload来获得文件句柄好了

嗯,两个都可以的,你的是直接while,而那上面那个有个read过程,

我想知道的是为什么二进制上传会报错,然后上传的文件就只是零字节,即没有写进去!
至于upload方式我也有试过,binmode就是会出错,不知道该怎么解决这个问题,我目前就只能把binmode给禁掉!


[Copy to clipboard] [ - ]
CODE:
#!c:/perl/bin/perl.exe
use CGI qw(:standard);
print header;
$fh = upload('uploaded_file');
open HT,'>fukkk.txt' or die 'open file error';
     while (<$fh>) {
           print HT;
     }

你先用这个测,再改

不行再贴好代码和apache的error log