我想将文件(图片)上传到网络服务器。
以下是我的代码片段,当点击按钮上传文件时,应该运行此代码。它运行正常,直到行open ( UPLOADFILE, ">", "$upload_dir/$filename" ) or die "$!";
,但服务器返回错误,说“没有这样的文件或目录”我已正确设置我的权限,open()
只是没有创建一个文件,我猜;任何帮助非常感谢。
编辑:我恢复了这个,当调试行被取消注释时,我从脚本中得到格式错误的标题。错误的标题= / srv / www / vhosts / nimml-dev.vbi。:mausdb.cgi
否则我得到:在lib_view.pl第1025行没有这样的文件或目录。
################################################################
# upload photo if requested
if (defined(param('job')) && param('job') eq "Upload File") {
use File::Basename; #for use of fileparse()
$CGI::POST_MAX = 1024 * 100000; #max size it 10MB
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = $global_var_href->{'URL_htdoc_basedir'} . "/jel_uploads";
my $filename = param("jel_photo");
my $query = new CGI;
if ( !$filename )
{
die "Photo too large to upload.";
}
my ( $name, $path, $extension ) = fileparse( $filename, '\..*');
$filename = $mouse_id . '_' . $name . $extension;
$filename =~ tr/ /_/;
$filename =~ s/[^$safe_filename_characters]//g;
if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Filename contains invalid characters"; }
my $upload_filehandle = $query->upload("jel_photo");
#use Cwd; use Data::Dumper; { local $Data::Dumper::Useqq = 1; print(Dumper("$upload_dir/$filename")); print(getcwd(), "\n"); }
open ( OUTFILE, ">$upload_dir/$filename" ) or die "$!"; binmode OUTFILE;
while (<$upload_filehandle> ) {print OUTFILE; } close OUTFILE;
}
答案 0 :(得分:1)
将open
失败的原因添加到您的邮件中:
open (UPLOADFILE, ">", "$upload_dir/$filename") or die "Can't open '$upload_dir/$filename': $!\n";