I am using PHP's mkdir function and I am having some difficulty with the $mode parameters. If I don't specify a parameter, I get UNIX 755 as the default permission settings of the new directory. I would like to set the permission to be UNIX 777, so I did that as you see here:
$mode = '0700';
mkdir($newdir, $mode);
When I do this a folder is created, but I cannot do anything with it. In fa开发者_运维技巧ct I cannot even delete it! All I can do is rename it via FTP...
I then tried setting $mode = '0600'; This makes a workable folder, but the permissions are set to UNIX 110. How is this possible? Shouldn't it be a UNIX value of 600? Is there some conversion that I am missing out here? Thanks.
The mode is supposed to be a number, not a string. Try $mode = 0700;
instead.
According to php.net manual mkdir function have this description:
bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
$mode here is an integer (not a string) and it must be started with "0" because it 8-based (not an 10-based).
Update: (from php.net) Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().
If you want to set it to be 0777, try this:
oldumask = umask(0);
mkdir('mydir', 0777);
umask($oldumask);
Read more on umask as the directory permissions are a combination of the umask and what you specify.
精彩评论