The stat function of PHP can return various properties of the file, see: http://php.net/manual/zh/function.stat.php
Where the Mode field represents the file's permissions, a numeric value of type int. The function below is to convert the int value to the format of the Linux form, such as 33206--rw-rw-rw-
1 /**2 * [Return-rwxrwxrwx file permission expression]3 * @param string $filePath [file path]4 * @return [string] []5 */6 functionGethumanfilestat ($filePath= ' ')7 {8 if(!file_exists($filePath) || !Is_file($filePath))9 return false;Ten One Clearstatcache(); A $stat=Stat($filePath); - $mode=$stat[' Mode ']; - the //reference libc ' s Fstat (): Http://man.he.net/man2/fstat - //8 file types for binary values - $typeMap=Array( -0140000 = ' Ssocket ', +0120000 = ' Llink ', -0100000 = '-file ', +0060000 = ' bblock ', A0040000 = ' Ddirectory ', at0020000 = ' CChar ', -0010000 = ' Pfifo ', - ); - - //8 binary values corresponding to each bit's permissions - $bitValueMap=Array( in' Mask ' = 0170000, -' Ubit ' = 0004000, to' Gbit ' = 0002000, +' Stickybit ' = 0001000, -' Ur ' = 0400, the' UW ' = 0200, *' UX ' = 0100, $' gr ' = 0040,Panax Notoginseng' GW ' = 0020, -' GX ' = 0010, the' or ' = 0004, +' Ow ' = 0002, A' Ox ' = 0001, the ); + - $str= ' '; $ //Filetype,first character $ $str.=array_key_exists($mode&$bitValueMap[' Mask '],$typeMap) ?substr($typeMap[$mode&$bitValueMap[' Mask ']], 0, 1): ' U '; - - //User Permission the $str.=$mode&$bitValueMap[' ur ']? ' R ': '-'; - $str.=$mode&$bitValueMap[' UW ']? ' W ': '-';Wuyi $str.=$mode&$bitValueMap[' UX ']? ($mode&$bitValueMap[' Ubit ']? ' s ': ' X '): ($mode&$bitValueMap[' Ubit ']? ' S ': '-'); the - //Group Permission Wu $str.=$mode&$bitValueMap[' Gr ']? ' R ': '-'; - $str.=$mode&$bitValueMap[' GW ']? ' W ': '-'; About $str.=$mode&$bitValueMap[' GX ']? ($mode&$bitValueMap[' Gbit ']? ' s ': ' X '): ($mode&$bitValueMap[' Gbit ']? ' S ': '-'); $ - //Other Permission - $str.=$mode&$bitValueMap[' or ']? ' R ': '-'; - $str.=$mode&$bitValueMap[' Ow ']? ' W ': '-'; A $str.=$mode&$bitValueMap[' Ox ']? ($mode&$bitValueMap[' Stickybit ']? ' t ': ' X '): ($mode&$bitValueMap[' Stickybit ']? ' T ': '-'); + the Clearstatcache(); - return $str; $}
Reference documents:
http://php.net/manual/zh/function.stat.php
Http://technosophos.com/2012/02/15/php-mode-strings-stat-and-stream-wrappers.html
Http://man.he.net/man2/fstat
Convert the file permissions from stat () in PHP to the Linux form