PHP文件夹权限问题 [英] PHP folder permissions problem

查看:94
本文介绍了PHP文件夹权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP创建一个文件夹,然后在其中创建另一个文件夹.

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)

目录/home/site/newdir 已创建,但该目录的用户为" apache "

The directory /home/site/newdir is created but the user of that directory is "apache"

现在,做

mkdir("/home/site/newdir/anotherdir",0777);

不会在newdir中创建另一个目录.

doesnt create another directory inside newdir.

请帮助.我认为这是一个所有者问题. 我也无法使用chmod()更改所有者.所有者保持不变.

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 ?

<?php
error_reporting(E_ALL);

mkdir("./m",0777);  // works
mkdir("./m/v",0777); // doesnt work

页面上没有错误.

var_dump(is_writeable("./m")) // returns bool(true)

:此问题已修复.对于可能面临相同问题的其他人,这是因为PHP的安全模式为"on".仍然不知道安全模式到底能做什么的原因,并不能使您创建嵌套目录.

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.

推荐答案

mkdir()创建的目录上的模式受当前umask的影响,这就是chmod()对您不起作用的原因.

The mode on the directory created by mkdir() is affected by your current umask, which is why chmod() is not working for you.

尝试:

$old_mask = umask(0);
mkdir("/home/site/newdir/anotherdir",0777);
umask($old_mask);

这篇关于PHP文件夹权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆