我基本上是这样的
就1个文件(upfile1.cgi), 表单提交本文件
加了$CGI:OST_MAX参数还是一样的问题,3K以下文件上传后正常可以使用,3K到10K文件上传后没法用,超过10K的上传不了(界面无响应)。已经启用了binmode(FILE);二进制传输,怎么还会出错? 高手指点一下,再次感谢~
所有测试代码如下:
------------------------------------------------------------------------------------------
#!/usr/bin/perl
## 定义初始参数 ##
use CGI;
$CGI::DISABLE_UPLOADS = 0;
$CGI::POST_MAX = 1024 * 1024 ;
my $maxsize = 1024;
my $basedir="/test";
my $query=CGI->new();
my $action=$query->param('action');
my $upfile=$query->upload('upfile');
my %Mode = (
'propage1' => \&propage1,
'propage2' => \&propage2,
);
if ($Mode{$action}) {
$Mode{$action}->();
} else {
&propage1;
}
## 显示界面1 ##
sub propage1 {
my $showit = qq~
<form action=upfile1.cgi method=post enctype='multipart/form-data'>
<input type=hidden name='action' value='propage2'>
请选择上传文件:<input type=file size=26 name='upfile'><br><br>
<input type=submit class=btn value=\" 立即上传 \"></form>~;
print $showit;
}
## 显示界面2(处理文件上传) ##
sub propage2 {
my $upfile=$query->upload('upfile');
my $size = (stat($upfile))[7];
&error("<br>文件大小不能超过 1M !") if ($size > $maxsize * 1024);
my $showit;
if ($upfile) {
my ($tmpfilename) = $upfile =~ m|([^/:\\]+)$|;
my ($buffer);
open (FILE,">$basedir/$tmpfilename");
binmode($upfile);
binmode(FILE);
while (read($upfile,my $buffer,2048)) {
print FILE $buffer;
}
close (FILE);
close ($upfile);
$showit = qq~<br>上传文件成功!~;
}else {
$showit = qq~<br>没有选择配置文件!~;
}
print $showit;
}
------------------------------------------------------------------------------------------