Page 1 of 1

Problems renaming a file

Posted: Thu Nov 30, 2006 4:28 am
by Longlands
I have written a script that writes a string to a file. The file already exists and has its permissions set to 777.

In further developing the script I decided that rahter than just overwriting the existing instance of the file (which works fine) I'd rather kee a copy of the exisitng file before overwriting it.

It seems logical to rename the existing file before writing the new one, but I'm hitting up against permission problems.

Here is the code:

Code: Select all

110: if (file_exists('myfile.htm')) {
111:    rename( 'myfile.htm', 'myfile.old' );
112: }
113:
114: $handle = fopen('myfile.htm', 'w');
115: fwrite($handle, $string);
116: fclose($handle);
Here is the error message:
Warning: rename(myfile.htm,myfile.old): Permission denied in xxx.php on line 111

What am I missing?

Martin

Posted: Thu Nov 30, 2006 11:53 pm
by feyd
Either the user you are running under doesn't have permissions to rename the file or isn't allowed to execute certain operations in the directory.