当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP DirectoryIterator getPerms()用法及代码示例


DirectoryIterator::getPerms()函数是PHP中的内置函数,用于获取当前DirectoryIterator项的权限。

用法:

int DirectoryIterator::getPerms( void )

参数:该函数不接受任何参数。


返回值:此函数以十进制整数形式取消文件许可权。

以下示例程序旨在说明PHP中的DirectoryIterator::getPerms()函数:

示例1:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs while directory is valid 
while ($directory->valid()) { 
  
    // If not a dot folder 
    if (!$directory->isDot()) { 
        $perms = substr(sprintf('%o', $directory->getPerms()), -4); 
  
        // Display the filename with permission 
        echo $directory->getFilename() . " " 
            . " | Permission: " . $perms . "<br>"; 
    } 
    $directory->next(); 
} 
  
?>

输出:

applications.html | Permission: 0666
bitnami.css | Permission: 0666
dashboard | Permission: 0777
favicon.ico | Permission: 0666
geeks.PNG | Permission: 0666
gfg.php | Permission: 0666
img | Permission: 0777
index.php | Permission: 0666
webalizer | Permission: 0777
xampp | Permission: 0777

示例2:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs for each element of directory 
foreach($directory as $dir) { 
      
    // If not a dot folder 
    if (!$dir->isDot()) { 
        $perms = substr(sprintf('%o', $dir->getPerms()), -4); 
  
        // Display the filename with permission 
        echo $dir->getFilename() . " " 
                . " | Permission: " . $perms . "<br>"; 
    } 
} 
  
?>

输出:

applications.html | Permission: 0666
bitnami.css | Permission: 0666
dashboard | Permission: 0777
favicon.ico | Permission: 0666
geeks.PNG | Permission: 0666
gfg.php | Permission: 0666
img | Permission: 0777
index.php | Permission: 0666
webalizer | Permission: 0777
xampp | Permission: 0777

注意:此函数的输出取决于服务器文件夹的内容。

参考: https://www.php.net/manual/en/directoryiterator.getperms.php



相关用法


注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | DirectoryIterator getPerms() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。