【发布时间】:2012-01-03 12:06:35
【问题描述】:
我有这个 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;
}
如果脚本没有问题,我还需要检查哪些其他内容? 谢谢。
编辑:我在日志中有这个:超时等待 CGI 脚本的输出。 我该如何摆脱这个?我在 Google 上找不到明确的答案。
【问题讨论】:
标签: perl upload cgi large-files