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.
Does chmod(); always work?
Moderator: General Moderators
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Does chmod(); always work?
chmod() works fine on *nix systems. Windows support is spotty.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Does chmod(); always work?
chmod won't work unless you have privilege to actually change the file permissions
Re: Does chmod(); always work?
That is - you should either be root, or the owner of the file.Mark Baker wrote:chmod won't work unless you have privilege to actually change the file permissions
There are 10 types of people in this world, those who understand binary and those who don't
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Does chmod(); always work?
That is - any files I create in PHP are owned by PHP, which means I can chmod them?VladSun wrote:That is - you should either be root, or the owner of the file.Mark Baker wrote:chmod won't work unless you have privilege to actually change the file permissions
Re: Does chmod(); always work?
Yes.kaisellgren wrote:That is - any files I create in PHP are owned by PHP, which means I can chmod them?VladSun wrote:That is - you should either be root, or the owner of the file.Mark Baker wrote:chmod won't work unless you have privilege to actually change the file permissions
Indeed, most probably files are owned by the Apache user.
There are 10 types of people in this world, those who understand binary and those who don't
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Does chmod(); always work?
Should really be by daemon, or by the user specified in apache's httpd.conf.VladSun wrote:Indeed, most probably files are owned by the Apache user.
Of course, daemon need not actually exist as a *nix user on the server.
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: Does chmod(); always work?
I tried running this script in the ROOT folder of three different servers:
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?
Code: Select all
<?php
mkdir('adirectory',0777);
fopen('adirectory/afile.php','w');
chmod('adirectory/afile.php',0777);
?>Are there servers where you can't make php to create files/folders into the root?