【发布时间】:2014-08-20 20:53:22
【问题描述】:
此代码在我的本地 xampp apache 服务器中运行良好。我在具有不同 IP 地址系统的局域网中运行相同的代码。该文件无法打开,我无法将其写入预期的目录。请做需要的?提前致谢。
我正在通过下面的代码传递 xml 文件。
#!"C:\xampp\perl\bin\perl.exe"
#!"172.18.5.23:\xampp\perl\bin\perl.exe"
#!\usr\bin\perl -wT
#!perl
use strict;
use warnings;
use CGI;
my $query = new CGI;
print $query->header( "text/html" );
print <<END_HERE;
<html>
<head>
<title>My First CGI Script</title>
</head>
<body bgcolor="#FFFFCC">
<h1>Welcome to Perl CGI</h1>
<form action="/cgi-bin/inputxml.cgi" method="post"
enctype="multipart/form-data">
<p>Files to Upload: <input type="file" name="xml" /></p>
<p><input type="submit" name="Submit" value="Submit Form" /></p>
</form>
</body>
</html>
END_HERE
将xml文件发送到下面的代码.....
#!"C:\xampp\perl\bin\perl.exe"
#!"172.18.5.23:\xampp\perl\bin\perl.exe"
#!\usr\bin\perl -wT
#!perl
use strict;
use CGI;
use Cwd 'abs_path';
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use File::Basename;
$CGI::POST_MAX;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $query = new CGI;
my $cgi = new CGI;
my $file = $cgi->param('xml');
my $lines;
open(DATA,"<$file") or die "Can't open data";
print $query->header ( );
$lines = <DATA>;
close(DATA);
$lines =~s{darling}{CGI}ig;
print $lines;
print abs_path($file);
open(OUT, '>dirname($file)."\\out_".basename($file)');
print OUT $lines;
close(OUT);
print $query->header ( );
print <<END_HERE;
【问题讨论】:
-
你需要开始检查错误,例如
open(DATA,"<$file") or die "Can't open data";变成open(DATA,"<$file") or die "Can't open data: $!";。另见perldoc open -
我也是这样做的,但显示的相同错误无法从文件中打开数据。