PHP文件夹权限问题

编程入门 行业动态 更新时间:2024-10-13 02:21:00
本文介绍了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文件夹权限问题

本文发布于:2023-11-28 15:05:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642897.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   权限   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!