【发布时间】:2014-10-13 08:32:13
【问题描述】:
我将读取和写入 xml 文件。 我使用下面的 html 代码上传 xml 文件。 如果我将 xml 文件放在 cgi-bin 文件夹中,它将执行并显示
#!"C:\xampp\perl\bin\perl.exe"
use strict;
use warnings;
use CGI;
my $cgi = new CGI;
print $cgi->header( "text/html" );
print <<END_HERE;
<html>
<head>
<title>My First CGI Script</title>
</head>
<body bgcolor="#FFFFCC">
<p>Welcome to Perl CGI</p>
<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 文件放在任何其他文件夹或驱动器中(cgi-bin 文件夹除外),它会显示 Can't open data at C:/xampp/cgi-bin/inputxml.cgi
#!"C:\xampp\perl\bin\perl.exe"
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 $cgi = new CGI;
print $cgi->header ( );
my $file = $cgi->param('xml');
my $lines;
open(DATA,"<$file") or die "Can't open data $!";
$lines = <DATA>;
close(DATA);
print $lines;
print abs_path($file);
open(OUT, '>dirname($file)."\\out_".basename($file)');
print OUT $lines;
close(OUT);
print <<END_HERE;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thanks!</title>
<style type="text/css">
img {border: none;}
</style>
</head>
<body>
<p>Thanks for uploading your file!</p>
</body>
</html>
END_HERE
print "Welcome Come Again";
我想在没有 cgi-bin 文件夹的任何文件夹或驱动器中执行 xml 文件,请任何人帮助,在此先感谢。
【问题讨论】:
-
Dave Cross 非常友好地在您之前关于此脚本的问题中给了您很多指示:How to upload and open a file in xampp apache server using CGI Perl Script? 在提出后续问题之前解决他指出的所有问题是明智的。