我有一个 Javascript/Ajax 文件上传器(https://github.com/Valums-File-Uploader/file-uploader),它可以在 latin-1 编码的网页上正常工作。现在我尝试在 UTF-8 环境中使用它,但它失败了。
这是我的代码(我只需要变量中的图像,保存在其他地方完成):
sub parseMultiPart{
use CGI;
use IO::Handle;
use Encode;
$CGITempFile::TMPDIRECTORY = $ENV{ADFRAME_TMP_FILES};
$CGI::POST_MAX=1024 * 1024 * 5;
#$CGI::PARAM_UTF8=1;
my $cgi = new CGI;
foreach $key ($cgi ->param) {
my $upload = $cgi->upload($key);
if(defined $upload) {
# THIS DOES NOTHING SINCE UPLOAD IS NOT DEFINED
my $file=$cgi->param($key);
binmode $upload;
my $data;
while (read($upload_file, $upload, 1024)) {
$main::in{$key} .= $data;
}
$main::inct{$key} = $cgi->uploadInfo($file)->{'Content-Type'};
}
else {
my @val = $cgi->param($key);
# THIS DOES THE WORK
if (scalar @val == 1) {
$main::in{$key} = $val[0];
}
# /
else {
$main::in{$key} = \@val; # save value as an array ref
}
}
}
}
1;
然后在下一步中:
if (open (HI, ">$storePath/$filename")) {
binmode HI;
print HI $data;
close(HI);
}
这里有几个问题:
CGI->upload()
不认为这是上传。我现在才注意到,因为它从来没有引起任何问题。- 使用
multipart/formdata
会导致服务器中止并且不发送任何内容。 - 像这样使用它,我收到一条
Wide character in print
消息。 - 如果我
encode $val[0]
不会收到消息,则生成的文件仍然已损坏。 - 如果
binmode $val[0]
我得到wide characters in print
有人可以帮忙吗??
谢谢,
托马斯
编辑:这是“关注 TCP 流”:
POST /cgi-bin/adframe/upload/image_upload.html?ITEM_ID=1&CATEGORY=1_1&qqfile=button_logout.gif HTTP/1.1
Host: productspecial
Connection: keep-alive
Content-Length: 583
Origin: http://productspecial
X-Mime-Type: image/gif
X-Requested-With: XMLHttpRequest
X-File-Name: button_logout.gif
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11
Content-Type: application/octet-stream
Accept: */*
Referer: http://productspecial/cgi-bin/adframe/online_produktdatenbank/1_komplettbikes/1_1_fullsuspension/1_1_fullsuspension.html?ITEM_ID=1&id=134149338812700131663
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
GIF89aD......................................................................................................!.......,....D........ud...Y.*y....qJ....8.....6..[..rh,....ez..lI.q.D....&........n.....B.....>..L..u.............$...........}..............................}..}........................}....}...}.........}...................}...4h.............A...H.(P.....q..qB....<.8.CI..I..4y..H..^Z..kB...=t.S...>......(J.D{*U*R.@z..R...@0.
.>.. k@
...@.....g..m%....p.V.K.n].t..........I.,A0a....^l......
n...a..+..........V....p.T.FMa5j..N..M.....s......
.y.........+_..A....K.N.....;HTTP/1.1 200 OK
Date: Thu, 05 Jul 2012 13:32:09 GMT
Server: Apache/2.2.20 (Ubuntu)
Cache-Control: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 104
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
.............MNN-..*)*M.I..I.R.O.-...MLO-./J,.wqus....+.KW.)-..R..utw.7.C..4SKsSK...4u...*..5...~.
.Y...