Windows操作系统中的函数chmod与linux中没有相似之处

时间:2013-09-13 09:05:07

标签: php linux windows chmod

PHP: 当我在Windows中chmod 777文件时,它转换为33060。 我想创建功能转换33060到777。 喜欢这个

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

并使用:

echo convertperm(33060); //return 777
你能帮我吗?谢谢!

1 个答案:

答案 0 :(得分:0)

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

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

但是,Windows不是Unix:您从stat depends on the file name extension获得的执行权限。 Windows版chmod can only be used to make a file read-write or read-only;你不能删除“阅读”permssion。此外,“所有者”,“组”或“其他”没有单独的权限,因为Windows上不存在用户组的Unix概念。

例如,对于33060,上述函数返回444,表示只读权限。如果您在理论上将权限设置为777,则应该返回666(Windows chmod忽略执行位),因此您的结尾可能存在错误。请确保use an octal constant when you call chmod

chmod($filename, 0777);