我想将文件上传添加到现有的网页上。网页文件上传总是被损坏
每当我上传我得到一个损坏的文件。
我确保在文件句柄上设置binmode
。我也有我的输入enxtype设置为multipart/formdata
在我的形式。
我的代码如下
$article{upload_file_name} = $cgi->param('upFile');
$article{upload_file} = $cgi->upload('upFile');
if ($article{upload_file_name} ne "" or $article{upload_file_name} ne null) {
open(UPLOADS, ">$uploads_dir/$article{upload_file_name}")
or die "Could not open $uploads_dir/$article{upload_file_name}";
binmode UPLOADS;
while (<$article{upload_file}>) {
print UPLOADS;
}
close UPLOADS;
}
我也试过这个
$article{upload_file} = $cgi->param('upFile');
if ($article{upload_file} ne "" or $article{upload_file} ne null) {
open(UPLOADS, ">$uploads_dir/$article{upload_file}")
or die "Could not open $uploads_dir/$article{upload_file}";
binmode UPLOADS;
while (<$article{upload_file}>) {
print UPLOADS;
}
close UPLOADS;
}
首先,您需要在脚本的顶部添加'use strict;'和'use warnings'all';';在Perl中没有'null',所以'$ article {upload_file_name} ne null'检查文件名是否等于文本文本“null”。 – ThisSuitIsBlackNot
你是否有一个子程序或常量名称为'null'定义的地方?除非您不使用strict,否则您的文本行应该是语法错误。 Perl中没有'null'。你想'undef',但是你不能用'ne'来检查'undef'。事实上,执行if($ article {upload_file_name}){...}就足够了,因为只要有非空或者undef的值,这个值就是真的。 – simbabque
参见[undef](http://p3rl.org/undef)和[defined](http://p3rl.org/defined)。 – choroba