PHP创建具有另一个权限的目录 [英] PHP Create directory with permissions of another

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

问题描述

我想创建一个具有$ another权限的目录$ one:

I would like to create a directory $one with the permissions of $another:

mkdir($one, fileperms($another));

在我看来,上述方法可能无法正常工作。请帮助我找到问题。

It seems to me that the above could doesn't work correctly. Please help me find the problem.

我也尝试过:

mkdir($one);
chmod($one, fileperms($another));

编辑以澄清

$one = "/tmp/somedir"
$another = "/tmp/anotherdir"


推荐答案

fileperms($ another)没有返回您期望的结果,有很多信息比您需要。

fileperms($another) is not returning what you expect it to, there is much more information than you need.

来自文档-


在大多数平台上,返回值还将包含有关文件名的文件类型的信息。

on most platforms the return value will also include information on the type of file given as filename.

要解决这个问题,您必须从 fileperms()获取所需的子字符串。

To account for that you'll have to get the substring you need from fileperms()

$one = "/tmp/somedir";
$another = "/tmp/anotherdir";
mkdir($one, substr(fileperms($another), -4));

这篇关于PHP创建具有另一个权限的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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