问题
I am trying to create a folder and then another folder within it using PHP.
If this is the directory structure I have
/home/site (owner : user1)
Now, I create the folder using
mkdir("/home/site/newdir",0777); (user : apache)
The directory /home/site/newdir is created but the user of that directory is "apache"
Now, doing
mkdir("/home/site/newdir/anotherdir",0777);
doesnt create another directory inside newdir.
Please help. I think its a owner issue. I cannot change the owner using chmod() either. The owner remains the same.
What might be causing this ?
EDIT :
<?php
error_reporting(E_ALL);
mkdir("./m",0777); // works
mkdir("./m/v",0777); // doesnt work
And no errors on the page.
var_dump(is_writeable("./m")) // returns bool(true)
EDIT : This has been fixed. For others who might be facing the same issue, It was because of PHP's safe mode being "on". Still dont know the reason behind what exactly does safe mode do that doesnt let you create nested directories.
But it works now. Thanks all for reading.
回答1:
The mode on the directory created by mkdir()
is affected by your current umask, which is why chmod()
is not working for you.
Try:
$old_mask = umask(0);
mkdir("/home/site/newdir/anotherdir",0777);
umask($old_mask);
来源:https://stackoverflow.com/questions/7372891/php-folder-permissions-problem