我想將文件上傳添加到現有的網頁上。網頁文件上傳總是被損壞
每當我上傳我得到一個損壞的文件。
我確保在文件句柄上設置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