0

我想要做的是写入一个文本文件。但是当我单击提交按钮时,控制台显示错误:不允许加载本地资源:file:///C:/xampp/cgi-bin/test.pl

#!"C:\xampp\perl\bin\perl.exe"

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $cgi = CGI->new;

print $cgi->header,
      $cgi->start_html,
      $cgi->start_form(-action=>'C:\xampp\cgi-bin\test.pl'),
      $cgi->textfield(-name=>'myString'),
      $cgi->submit,

      $cgi->end_form,

      $cgi->end_html;

测试.pl

#!"C:\xampp\perl\bin\perl.exe"
# print "Content-type: text/html; charset=iso-8859-1\n\n";

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $cgi    = CGI->new;
my $string = $cgi->param("myString");

print $cgi->header,
      $cgi->start_html('Writing to a file');

open my $fh, '>', './write.txt' or die "failed to open './write.txt' $!";
print $fh $string;
close $fh;

print $cgi->p( "qq(write.txt should contain ".$string.") ");
print $cgi->end_html;

可能是什么问题?test.pl 是“C:\xampp\cgi-bin\test.pl”

4

1 回答 1

3

$cgi->start_form(-action=>'C:\xampp\cgi-bin\test.pl'),

您需要通过您的 Web 服务器访问该脚本。您必须提供一个 HTTP URL。

于 2013-07-20T20:13:06.177 回答