[ back to toc ]

Perl/CGI Programming

Date: 2002/06/11 13:18

Q:
Hello, I have been having problems trying to write Perl/CGI programs for
my website. I think I am having trouble understanding how the open
function works in a program on the server. If I am running a program from
the cgi-bin directory and trying to open a file from another directory,
how would I do that? I have been putting the following line in my program
to do that:

open( F, "$root/dir/file.txt") || error( $e, "File does not exist.");

The variable $root is what I get from the $ENV{DOCUMENT_ROOT} variable.
For some reason it will not open the file. It says to me that the file
does not exist every time I run the program. What could be wrong?
A:
The only reason for your program not being to able to open the file is
that the file has permission that does not allow the web server to see the
file. Check that you can see the file via the web simply typing the URL of
the file directly. If you can not then the web server can not access the
file and you have to alter the permission.

The web server is usually executed by the "pseudo" user www-data and the
CGI programs started by the web server also belong to this user. You have
to alter the permission of the file so that the web server user has access
to it.

regards,
Peter

[ back to toc ]