📜  PHP | DirectoryIterator getPerms()函数

📅  最后修改于: 2022-05-13 01:56:49.245000             🧑  作者: Mango

PHP | DirectoryIterator getPerms()函数

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

句法:

int DirectoryIterator::getPerms( void )

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

返回值:此函数将文件权限重新设置为十进制整数。

下面的程序说明了PHP中的 DirectoryIterator::getPerms()函数:

方案一:

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 . "
";     }     $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

方案二:

isDot()) {
        $perms = substr(sprintf('%o', $dir->getPerms()), -4);
  
        // Display the filename with permission
        echo $dir->getFilename() . " " 
                . " | Permission: " . $perms . "
";     } }    ?>

输出:

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