Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make a Perl script open a file in a parent directory?

Status
Not open for further replies.

theblackperl

Programmer
Dec 15, 2005
1
US
How do I make a Perl script open a file that is not located in cgi-bin or its subdirectorys? I can open and modify files that are in the same directory as my script, but how do I do so for a file in a parent directory?

Thanks
 
use chdir() to change into the desired directory then open the file or use the full machine path to the directory/file:

open(FH,'path/to/dir/file.txt');
 
Assuming that you are using Linux or Unix, you may have a permissions issue here.
Assuming (again) that you are using Apache then the chances are that your code runs as the user "apache" and therefore will only have access to any directories that the user "apache" has permissions to access.
Check 1: Ensure that the "apache" user has permission to access a file in the parent directory.
Check 2: Try something like "open FH, '../myfile';" in your code. Check the return code of that open and see if you succeeded. The "../" will make perl look in the parent directory of cgi-bin.


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top