PHP: fopen error using absolute address

software development

#1

Reading through the forums and support wiki, it is my understanding that I can use fopen with an absolute file address (e.g. /home/user/sitename.com/testing.txt). However, I am consistently getting the following error when I use fopen to open a file for writing:

Warning: fopen(/home/user/sitename.com/testing.txt) [function.fopen]: failed to open stream: Permission denied in [script name]

I’m using this code to establish the output filename then open that file for writing:

$outputfile = $_SERVER[‘DOCUMENT_ROOT’] . “/testing.txt”;

if (!$handle = fopen($outputfile, ‘w’)) {
print “Cannot open file ($outputfile)”;
exit;
}

The goal of my script is to write xml files to my server (for use with the Flash Image Rotator supplied at media.dreamhost.com)

If I load a dummy “testing.txt” file to my server and use the ‘r’ option with fopen, I do not get an error. That demonstrates that my file address is correct. But any of the fopen options, such as ‘w’ or ‘r+’, which open a file for writing result in the error above.

I am using PHP 4.4.4.

Thanks for any suggestions!


#2

Make sure you have set permissions properly (CHMOD), or you won’t be able to write anything.


si-blog | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#3

Thanks for the straightforward solution. I updated permissions on the directory I’m writing the files to and things appear to be working properly now. Much appreciated!