apache - 当文件被压缩时 Perl 上传失败

标签 apache perl upload mime-types

我有一个设计用于上传多个文本文件的表单,因此我已将 HTML 表单中的 mime 类型设置为

enctype="multipart/form-data"

我正在使用以下脚本

#!/usr/bin/env perl -wT

use strict;
use warnings;
use open qw(:std :encoding(UTF-8));
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $cgi = CGI->new();

但是,人们有可能会上传 gzip 文件。我想防范它,但是当我上传 gzip 文件时,只要在 httpd error_log 中创建了新的 CGI 对象并显示此错误消息,脚本就会崩溃。

...
test.cgi: utf8 "\\xA3" does not map to Unicode at (eval 16) line 5.
test.cgi: utf8 "\\xB5" does not map to Unicode at (eval 16) line 5.
test.cgi: Malformed multipart POST

我如何能够上传多个纯文本文件,并且在有人上传 gzip 文件时死机?

最佳答案

:std 影响 STDIN、STDOUT 和 STDERR,STDIN 用于从 Web 服务器接收信息。

添加编码层后要么将其删除

use open qw( :std :encoding(UTF-8) );
BEGIN { binmode( STDIN ); }

或者避免首先添加它。

use open qw( :encoding(UTF-8) );
BEGIN {
   binmode( STDIN );
   binmode( STDOUT, ':encoding(UTF-8)' );
   binmode( STDERR, ':encoding(UTF-8)' );
}

关于apache - 当文件被压缩时 Perl 上传失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73023422/

相关文章:

php - mod 重写在 & 处停止,因此找不到名为 'Britain-&-Ireland.php' 的页面

windows - 视频卡在 Perl 脚本中的 system(1, @commands) 上

mysql - 如何在Windows后台运行apache的httpd守护进程?

perl - 如何在 IMAP 邮件主题中搜索非 ASCII 文本

perl - readpipe 以什么编码返回执行命令的结果?

android - 上传 Google Drive API Retrofit 2

c# - "The given path' 格式不受支持。”

java - 如何使用 Java App Engine 将(图像)文件正确上传到 Google Cloud Storage?

wordpress - 如何找到服务器频繁关闭的根本原因

linux - 使用 HTACCESS 在 URL 中隐藏文件夹