我有这段代码:
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的空文件。我省略了与resize相关的部分,我仍然有代码。所以我确定文件没有正确上传。我错过了任何图书馆吗? 有什么帮助吗?Plz ..
答案 0 :(得分:3)
您需要更改
my $upload_filehandle =$query->param("img");
到
my $upload_filehandle =$query->upload("img");
希望它有所帮助。
答案 1 :(得分:2)
我弄清楚了原因:正如CGI.pm docs中指出的那样,表单的编码类型必须为multipart/form-data
。当我补充说,一切都有效。
答案 2 :(得分:0)
添加了“ENCTYPE ='multipart / form-data'”而不是编码。
> <form action="/post.pl" method="post" ENCTYPE='multipart/form-data'>
并且有效