Problems renaming a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Longlands
Forum Newbie
Posts: 15
Joined: Tue Oct 25, 2005 3:36 am

Problems renaming a file

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply