PHP - Unix系统如何获取文件的权限
PHP - How to get the permissions of a file in Unix system
我需要在PHP中获取Unix系统中文件的权限。我尝试了 stat()
和 fileperms()
方法,但都 returns 类似于 33188
、16877
。但我期待 755
、777
等权限值
你可以在这里使用fileperms()
功能:
clearstatcache();
echo substr(sprintf('%o', fileperms('demo')), -4);//0775
echo substr(sprintf('%o', fileperms('phptest/PHP_test')), -4);//0775
根据 回答的建议,您可以使用
is_readable()
, is_executable()
等命令。
按照Mark Baker in his comment, and , you can use fileperms()
函数的建议获取文件权限如下:
function getFilePermission($file) {
$length = strlen(decoct(fileperms($file)))-3;
return substr(decoct(fileperms($file)),$length); // "777" ,"755" for example
}
还有另一种选择。您还可以检查文件
希望对您也有帮助:-)
我需要在PHP中获取Unix系统中文件的权限。我尝试了 stat()
和 fileperms()
方法,但都 returns 类似于 33188
、16877
。但我期待 755
、777
等权限值
你可以在这里使用fileperms()
功能:
clearstatcache();
echo substr(sprintf('%o', fileperms('demo')), -4);//0775
echo substr(sprintf('%o', fileperms('phptest/PHP_test')), -4);//0775
根据 is_readable()
, is_executable()
等命令。
按照Mark Baker in his comment, and fileperms()
函数的建议获取文件权限如下:
function getFilePermission($file) {
$length = strlen(decoct(fileperms($file)))-3;
return substr(decoct(fileperms($file)),$length); // "777" ,"755" for example
}
还有另一种选择。您还可以检查文件
希望对您也有帮助:-)