我要做的是写入文本文件。但是当我点击提交按钮控制台显示错误:不允许加载本地资源: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;
test.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"
答案 0 :(得分:3)
$cgi->start_form(-action=>'C:\xampp\cgi-bin\test.pl'),
您需要通过Web服务器访问脚本。您必须提供HTTP URL。