fileperms() 函數可以返回文件或目錄的權限。此函數可以在成功或失敗時以數字形式返回權限。
用法
int fileperms ( string $filename )
示例1
<?php
echo substr(sprintf("%o", fileperms("/PhpProject/sample.txt")), -4);
?>
輸出
0666
示例2
<?php
$perms = fileperms("/PhpProject/sample.txt");
switch($perms & 0xF000) {
case 0xC000:// socket
$info = 's';
break;
case 0xA000:// symbolic link
$info = 'l';
break;
case 0x8000:// regular
$info = 'r';
break;
case 0x6000:// block special
$info = 'b';
break;
case 0x4000:// directory
$info = 'd';
break;
case 0x2000:// character special
$info = 'c';
break;
case 0x1000:// FIFO pipe
$info = 'p';
break;
default:// unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r':'-');
$info .= (($perms & 0x0080) ? 'w':'-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's':'x' ):
(($perms & 0x0800) ? 'S':'-'));
// Group
$info .= (($perms & 0x0020) ? 'r':'-');
$info .= (($perms & 0x0010) ? 'w':'-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's':'x' ):
(($perms & 0x0400) ? 'S':'-'));
echo $info;
?>
輸出
rrw-rw-
相關用法
- PHP fileperms()用法及代碼示例
- PHP fileperms( )用法及代碼示例
- PHP fileowner()用法及代碼示例
- PHP file_get_contents()用法及代碼示例
- PHP filetype()用法及代碼示例
- PHP filectime( )用法及代碼示例
- PHP filesize( )用法及代碼示例
- PHP fileinode()用法及代碼示例
- PHP filemtime( )用法及代碼示例
- PHP file()用法及代碼示例
- PHP filemtime()用法及代碼示例
- PHP file_exists( )用法及代碼示例
- PHP file_put_contents()用法及代碼示例
- PHP fileatime()用法及代碼示例
- PHP filectime()用法及代碼示例
- PHP filegroup()用法及代碼示例
- PHP fileatime( )用法及代碼示例
- PHP filetype( )用法及代碼示例
- PHP file_exists()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - Function fileperms()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。