0

PHP:当我在 Windows 中 chmod 777 文件时,它转换为 33060。我想创建函数将 33060 转换为 777。像这样

function convertperm($num) {
//do something
}

并使用:

echo convertperm(33060); //return 777

你能帮助我吗。谢谢!

4

1 回答 1

0

此函数以八进制返回来自输入的权限位,因此如果 Windows 上的文件权限与 Unix 上的文件权限相同,这对您有用:

function convertperm($num) {
    return 0777 & decoct($num);
}

但是,Windows 不是 Unix:您从中获得的执行权限stat 取决于文件扩展名. Windows 版本chmod 只能用于使文件为读写或只读;您无法删除“读取”权限。此外,“所有者”、“组”或“其他”没有单独的权限,因为 Windows 上不存在用户组的 Unix 概念。

例如,对于33060上述函数 return 444,表示只读权限。如果您在理论上将权限设置为 777,您应该返回 666(Windows chmod 忽略执行位),因此您可能存在错误。确保在调用时使用八进制常量chmod

chmod($filename, 0777);
于 2013-09-15T11:25:55.293 回答