在 CGI 上传中检查每个文件的长度而不是整个请求

发布于 2024-09-07 03:58:57 字数 433 浏览 2 评论 0原文

我正在尝试修改 Uber-Uploader perl 脚本,以便在检查上传是否满足最低要求时,它会检查每个文件,而不仅仅是整个请求。

我对 perl 不太有经验,不知道该怎么做。目前,该脚本只是执行此操作:

elsif($ENV{'CONTENT_LENGTH'} > $config{'max_upload_size'}){
my $max_size = &format_bytes($config{'max_upload_size'}, 99);
die("Maximum upload size of $max_size exceeded");
}

所做的只是检查请求的内容长度(包含多个文件),并在总计大于允许的最大大小时失败。

有没有办法检查每个文件?

注意:更改上传脚本不是一个选项。不要尝试

I am attempting to modify the Uber-Uploader perl script so that when an upload is checked if it meets the minimum requirements, it checks per file instead of just the entire request.

I'm not too experienced with perl, and don't know how to do this. Currently the script simply does this:

elsif($ENV{'CONTENT_LENGTH'} > $config{'max_upload_size'}){
my $max_size = &format_bytes($config{'max_upload_size'}, 99);
die("Maximum upload size of $max_size exceeded");
}

All that does is check the content length of the request (which contains multiple files), and fail when the total is greater than the max allowed size.

Is there a way to check it per file?

Note: Changing upload scripts is not an option. Don't try

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绻影浮沉 2024-09-14 03:58:57

我不确定“更改上传脚本不是一个选项”是什么意思,但是您尝试过这样的事情吗?

my $q = CGI->new();
my @files = $q->upload();

foreach my $file (@files){
    if ((-s $file) > $config{'max_upload_size'}){
        die("Maximum upload size of $file exceeded");
    }
}

(注意:这是未经测试的代码!!!!)

I'm not sure what you mean by "Changing upload scripts is not an option.", but have you tried something like this?

my $q = CGI->new();
my @files = $q->upload();

foreach my $file (@files){
    if ((-s $file) > $config{'max_upload_size'}){
        die("Maximum upload size of $file exceeded");
    }
}

(NOTE: this is untested code!!!!!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文