为什么此Perl CGI脚本无法正确上传图像? [英] Why is this Perl CGI script failing to upload images correctly?
本文介绍了为什么此Perl CGI脚本无法正确上传图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
use CGI;
use File::Basename;
use Image::Magick;
use Time::HiRes qw(gettimeofday);
my $query = new CGI;
my $upload_dir = "../images"; #location on our server
my $filename=$query->param("img");
my $timestamp = int (gettimeofday * 1000);
my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
$filename = $name ."_".$timestamp. $extension;
#upload the image
my $upload_filehandle =$query->param("img");
open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
然后我为图像调整大小。我的问题是图像未上传。我有一个名为$ filename的空文件。我省略了与调整大小有关的部分,但我仍然有代码。因此,我确定该文件未正确上传。我缺少图书馆吗?
有帮助吗?Plz ..
Then I do resize for the image. My problem is that the image is not uploaded. I have an empty file having the name of $filename. I omitted the part related to resize and I still have the code. So I'm sure that the file is not being uploaded correctly. Am I missing any library? Any help?Plz..
推荐答案
我弄清楚了原因:如 CGI.pm文档,表单的编码类型必须为 multipart / form-data
。当我添加时,一切正常。
I figured out why: As pointed out in the CGI.pm docs, the form's encoding type must be multipart/form-data
. When I added that, everything worked.
这篇关于为什么此Perl CGI脚本无法正确上传图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文