Page 1 of 1

Does chmod(); always work?

Posted: Sat Nov 22, 2008 10:49 am
by kaisellgren
Hi,

I'm wondering a thing that is maybe a bit more a *nix question. Anyhow, can I rely on chmod()? I need to often make directories and files writable undex *nix and asking user to chmod through FTP is not an option. Is this a bad thing - using a chmod? My application is targeted for LAMP setups.

Re: Does chmod(); always work?

Posted: Sat Nov 22, 2008 11:16 am
by Syntac
chmod() works fine on *nix systems. Windows support is spotty.

Re: Does chmod(); always work?

Posted: Sat Nov 22, 2008 12:22 pm
by Mark Baker
chmod won't work unless you have privilege to actually change the file permissions

Re: Does chmod(); always work?

Posted: Sat Nov 22, 2008 3:33 pm
by VladSun
Mark Baker wrote:chmod won't work unless you have privilege to actually change the file permissions
That is - you should either be root, or the owner of the file.

Re: Does chmod(); always work?

Posted: Sat Nov 22, 2008 6:57 pm
by kaisellgren
VladSun wrote:
Mark Baker wrote:chmod won't work unless you have privilege to actually change the file permissions
That is - you should either be root, or the owner of the file.
That is - any files I create in PHP are owned by PHP, which means I can chmod them?

Re: Does chmod(); always work?

Posted: Sat Nov 22, 2008 6:59 pm
by VladSun
kaisellgren wrote:
VladSun wrote:
Mark Baker wrote:chmod won't work unless you have privilege to actually change the file permissions
That is - you should either be root, or the owner of the file.
That is - any files I create in PHP are owned by PHP, which means I can chmod them?
Yes.
Indeed, most probably files are owned by the Apache user.

Re: Does chmod(); always work?

Posted: Sun Nov 23, 2008 5:06 am
by Mark Baker
VladSun wrote:Indeed, most probably files are owned by the Apache user.
Should really be by daemon, or by the user specified in apache's httpd.conf.
Of course, daemon need not actually exist as a *nix user on the server.

Re: Does chmod(); always work?

Posted: Sun Nov 23, 2008 3:31 pm
by kaisellgren
I tried running this script in the ROOT folder of three different servers:

Code: Select all

<?php
mkdir('adirectory',0777);
fopen('adirectory/afile.php','w');
chmod('adirectory/afile.php',0777);
?>
And it seemed to work create. One thing, the adirectory is not 0777, its 0755, but that's enough for me.

Are there servers where you can't make php to create files/folders into the root?