使用CGI perl将数据写入文件

使用CGI perl将数据写入文件,perl,Perl,我在使用CGI将数据写入文件时遇到问题。代码如下: #!/usr/bin/perl use strict; use warnings; use CGI ":standard"; print "Content-type:text/html \n\n"; open (FILE, '>', "file.txt") or die ("Could not open the file for writing...$!"); print FILE "something"; close(FILE);

我在使用CGI将数据写入文件时遇到问题。代码如下:

#!/usr/bin/perl
use strict;
use warnings;
use CGI ":standard";

print "Content-type:text/html \n\n";

open (FILE, '>', "file.txt") or die ("Could not open the file for writing...$!");
print FILE "something";
close(FILE);
上述代码给出了以下错误: “无法打开文件进行写入…权限在/var/www/cgi-bin/wfile.cgi第8行被拒绝。
文件的读写权限已经设置好…请帮助!!!

perl脚本将以apache/httpd/任何正在运行的用户的身份运行。您需要确保目录和文件可由该用户写入。为什么不先尝试写入
/tmp/

对于
www用户
,目录也允许文件的读写权限已设置“-为了什么?web服务器以什么用户的身份运行脚本?是的,最好的方法是一步一个脚印,这里。。。问题可能是缺少http服务器用户写入该文件的权限。。。不幸的是,检测http服务器用户名的方法取决于linux发行版,问题中没有指定此发行版…是。。现在开始工作了。。。但是是否可以将其重定向到另一个目录中的文件…?当然,您要在
open()
调用中指定要打开的文件。