Page 1 of 1

rename() madness......

Posted: Fri Jan 16, 2004 6:07 pm
by heepzahype
someone shoot me.... Please!
I am just geting started at this and cannot even get the rename() command to work.

I have a test file called rename.txt and an trying:

<?php
rename("/home/zmqqxh/public_html/rename.txt", "/home/zmqqxh/public_html/testrenamed.txt");
?>

The page returns:

Warning: rename(/home/zmqqxh/public_html/rename.txt,/home/zmqqxh/public_html/renameworked.txt): Permission denied in /home/zmqqxh/public_html/rename.php on line 2

So now I'm confused - what permissions?!?! How do I get this sorted - it's been making me mental for 2 hours now. 8O

Thanks in advance to any kind soul who can help me on this.

?>

Posted: Fri Jan 16, 2004 6:10 pm
by dull1554
you have read only access prolly, try chmod ing the file to 777----should do the trick

Posted: Fri Jan 16, 2004 6:22 pm
by McGruff
Each file or folder has an owner and group. The permissions set specify read, write and execute access for the owner, groups, and anonymous requests.

Rather than CHMOD 777 (which you can't do in php by the way since it's not the owner - use your ftp program), it might be better to create the file with php to begin with. This means that php is the owner and so it can be left on 755 or something to control access.

With 755, the first 7 specifies owner permissions: = rwx. Everything else gets 5 = r_x ie read and execute.

Note that, to write a file with php, php must have write permissions in that directory. You may need to CHMOD 777 the parent folder (ie if it's not owned by php), write the file with php, then CHMOD the parent back to 755 or whatever.

Once the file is written with php as the owner, parent permissions don't affect subsequent access by php hence you can close the folder down again.

Thanks

Posted: Sat Jan 17, 2004 6:02 am
by heepzahype
Thanks guys. Got it.

So, if I use FTP to upload then PHP will never have permission to perform file opertations (unless the file's permission is changed beforehand) - is this correct?

So, is there some way to upload with PHP then means it can own a whole directory and therefore avoid this whole issue? Or similarly change ownership of a file or directory once it has been created by something else?

Thanks again - amazing how a couple of lines of explination can clear up hours of confusion. :wink:

Re: Thanks

Posted: Sat Jan 17, 2004 6:15 am
by McGruff
heepzahype wrote:Thanks guys. Got it.

So, if I use FTP to upload then PHP will never have permission to perform file opertations (unless the file's permission is changed beforehand) - is this correct?

So, is there some way to upload with PHP then means it can own a whole directory and therefore avoid this whole issue? Or similarly change ownership of a file or directory once it has been created by something else?

Thanks again - amazing how a couple of lines of explination can clear up hours of confusion. :wink:
Yes - ftp creates files with a different owner to the UID php runs under. 777 opens files up for anything - not that you'd really want to except maybe temporarily.

If you do a dirinfo in your ftp program, you can see what owner/groups are set for files and folders.

AFAIK only the superuser can change a file's owner.