1
votes

I have a problem in writing data to a file using CGI. the code is as follows:

#!/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);

The above code is giving the following error: "Could not open the file for writing...Permission denied at /var/www/cgi-bin/wfile.cgi line 8. The read and write permission for the file is already set... Please help!!!

1
for the www-user as well? The directory permissions too?user1558455
"The read and write permission for the file is already set" — to what? And what user does the web server run the script as?Quentin

1 Answers

2
votes

The perl script will run as the user that apache/httpd/whatever is running as. You need to make sure that the directory and file is writeable by that user. Why not try writing to /tmp/ first.