【问题标题】:PHP - How to get the permissions of a file in Unix systemPHP - 如何在 Unix 系统中获取文件的权限
【发布时间】:2016-06-26 13:24:33
【问题描述】:

我需要在 PHP 中获得 Unix 系统中文件的权限。我尝试了stat()fileperms() 方法,但都返回类似33188,16877 的东西。但我期待755777 等权限值。

【问题讨论】:

  • 如果您阅读了PHP Docs for fileperms(),那么示例 #2 显示了如何将结果作为 rwx ...... PHP 文档可以帮助您,学习阅读它们
  • 谢谢@MarkBaker 我真的很想念它..
  • 提示:var_dump( base_convert('33188', 10, 8) )

标签: php file-permissions chmod


【解决方案1】:

根据Mark Baker in his commentShashank Shah's answer的建议,您可以使用fileperms()函数获取文件权限,如下所示:

function getFilePermission($file) {
      $length = strlen(decoct(fileperms($file)))-3;
      return substr(decoct(fileperms($file)),$length); // "777" ,"755" for example 
} 

还有另一种选择。也可以检查文件是否

希望它也能帮助你:-)

【讨论】:

    【解决方案2】:

    你可以在这里使用fileperms()函数:

    clearstatcache();
    echo substr(sprintf('%o', fileperms('demo')), -4);//0775
    echo substr(sprintf('%o', fileperms('phptest/PHP_test')), -4);//0775
    

    正如Ravi Hirani's 建议的答案,您可以使用 is_readable()is_executable() 等命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-23
      • 2016-06-29
      • 1970-01-01
      • 2012-04-15
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      • 2011-05-19
      相关资源
      最近更新 更多