파일시스템 함수 목록
PHP Manual

fileperms

(PHP 4, PHP 5, PHP 7)

filepermsGets file permissions

설명

int fileperms ( string $filename )

Gets permissions for the given file.

인수

filename

Path to the file.

반환값

Returns the file's permissions as a numeric mode. Lower bits of this mode are the same as the permissions expected by chmod(), however on most platforms the return value will also include information on the type of file given as filename. The examples below demonstrate how to test the return value for specific permissions and file types on POSIX systems, including Linux and Mac OS X.

For local files, the specific return value is that of the st_mode member of the structure returned by the C library's stat() function. Exactly which bits are set can vary from platform to platform, and looking up your specific platform's documentation is recommended if parsing the non-permission bits of the return value is required.

예제

Example #1 Display permissions as an octal value

<?php
echo substr(sprintf('%o'fileperms('/tmp')), -4);
echo 
substr(sprintf('%o'fileperms('/etc/passwd')), -4);
?>

위 예제의 출력:

1777
0644

Example #2 Display full permissions

<?php
$perms 
fileperms('/etc/passwd');

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' '-'));

// World
$info .= (($perms 0x0004) ? 'r' '-');
$info .= (($perms 0x0002) ? 'w' '-');
$info .= (($perms 0x0001) ?
            ((
$perms 0x0200) ? 't' 'x' ) :
            ((
$perms 0x0200) ? 'T' '-'));

echo 
$info;
?>

위 예제의 출력:

-rw-r--r--

오류/예외

실패 시, E_WARNING이 발생합니다.

주의

Note: 이 함수의 결과는 캐시에 저장합니다. 자세한 설명은 clearstatcache()를 참고하십시오.

Tip

PHP 5.0.0부터 이 함수는 몇몇 URL 래퍼를 사용할 수 있습니다. 기능적으로 stat() 패밀리를 지원하는 래퍼 목록은 Supported Protocols and Wrappers를 참고하십시오.

참고


파일시스템 함수 목록
PHP Manual