我有这个 Perl/CGI 来上传文件并在上传时获取上传的文件大小。
该脚本适用于 500MB 以下的文件,但缓冲区 (OUTFILE) 在大约 500MB 后停止写入文件。
这是部分代码:
$u_size = $ENV{'CONTENT_LENGTH'};
if ($u_size > $max_size) {send_error ("Upload too big. Maximum size is $max_size bytes and your file is $u_size bytes.");}
print_progress(0);
# Set up uploading function
$query = CGI->new(\&hook);
#define functions
sub hook {
if ($error) {return;}
if (time >= $next_print) {
$next_print = time + $delay;
my ($filename, $buffer, $bytes_read, $data) = @_;
if ($check_mime) {
$filename =~ m/\.([^\.]+)$/;
$ext = lc($1);
print $ext;
$check_mime = 0;
}
$percent = $bytes_read / $u_size;
$filename =~ m/\\([^\\]+)$/;
$filename = $1;
print_progress($percent, $u_size, $bytes_read, $filename);
}
}
sub print_progress {
open(PROG, '>'.$uploaded_file_progress);
print PROG '{"percent" : ' . ($_[0] * 100) . ', "total" : ' . $_[1] . ', "uploaded" : ' . $_[2] . ', "filename" : "' . $_[3] . '"}';
close PROG;
}
#############
$uphandle = $query->upload($query->param());
binmode $uphandle;
if (!$error) {
open OUTFILE, ">" . $uploaded_file;
binmode OUTFILE;
while($bytesread = read $uphandle, $buffer, 1024) {
print OUTFILE $buffer;
}
#while (<$uphandle>) {print OUTFILE $_;}
close OUTFILE;
}
如果脚本没有问题,我还需要检查哪些其他内容?
谢谢。
编辑:我在日志中有这个:WAITING CGI 脚本输出的超时。
我该如何摆脱这个?我在谷歌上找不到明确的答案。
最佳答案
我想你需要戳你的 apache TimeOut
apache conf 中的配置变量。
看到您正在使用 perl,这已在 perlmonks.org 上提出过几次,并且已弹出此链接作为回应。
http://www.stonehenge.com/merlyn/LinuxMag/col39.html
关于Perl/CGI 脚本在大量上传时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8221174/