Forum Moderators: coopster

Message Too Old, No Replies

PHP mkdir() Issue

cannot make chmod 777

         

wfernley

4:30 pm on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey everyone,

hopefully there is an easy answer to this.

I'm trying to get php to create a directory specific for each user when they register on my website. I am using the mkdir() function for this:

mkdir("/var/www/mysite/images/houses/uploads/userid", 0777);

For some reason, the directory is created but not with the CHMOD of 777. Instead, it is created with CHMOD 755. This does not give the user rights to "write" in the directory.

Am I doing something wrong?

Thanks in advance for your help!

Wes

eelixduppy

5:12 pm on Jun 15, 2006 (gmt 0)



According to php.net, the mode is defaultly set to 0777. Try omitting the mode argument to see if that fixes your problem.

wfernley

5:33 pm on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately, it doesn't. It creates it with no CHMOD.

wfernley

5:48 pm on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alright I found a fix.

I first use mkdir() to make the directory and then I use chmod() to change the rights ;) works!

Thanks for your help!

eelixduppy

5:49 pm on Jun 15, 2006 (gmt 0)



The problem seems to be that of umask [us2.php.net]. Change umask like this before you create the directory:
$old_mask = umask(0);
mkdir("/var/www/mysite/images/houses/uploads/userid", 0777);
umask($old_mask);

Good luck!