Linux下创建文件夹和权限
我想创建一个文件夹并设置其权限。 在windows上运行得很好,但是当我转向linux时, 它有权限问题。
//Make new directory
$directory = dirname($this->fileName);
if(!is_dir($directory)) {
if (!mkdir($directory, 0777, true))
die('Failed to create folders...');
} else {
die('ah ok...');
}
为此,我必须手动将文件夹权限设置为 777
。 然后应用程序就可以成功运行。
然后我再次删除现有文件夹来测试它,无法再次创建,因为 权限被拒绝,无法创建文件夹。
I wanted to create a folder and set its permission.
It was working fine with windows, but when I shifted to linux,
it had permission problems.
//Make new directory
$directory = dirname($this->fileName);
if(!is_dir($directory)) {
if (!mkdir($directory, 0777, true))
die('Failed to create folders...');
} else {
die('ah ok...');
}
For this to work, I have to set the folder permission manually to 777
.
Then after that the application can run successfully.
Then I delete the existing folder again to test it, cannot create again because
permission denied, it fails to create folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查您的
umask()
并设置它到0
。例如,如果您的 umask 是0022
,那么您新创建的目录在创建时将具有 0755 权限,而不是 0777。Check your
umask()
and set it to0
. If your umask is0022
for example, your newly created directory will have permission 0755 instead of 0777 when you create it.