chown 함수

(PHP 4, PHP 5, PHP 7, PHP 8)

chown — 파일 소유자 변경


설명

chown(string $filename, string|int $user): bool

filename의 소유자를 사용자 user로 변경하려고 시도합니다. 수퍼유저만 파일 소유자를 변경할 수 있습니다.


매개변수

filename
파일의 경로입니다.
user
사용자 이름 또는 번호.

반환 값

성공하면 true를, 실패하면 false를 반환합니다.


Examples

예제 #1 간단한 chown() 사용법

                  
<?php

// File name and username to use
$file_name= "foo.php";
$path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
$user_name = "root";

// Set the user
chown($path, $user_name);

// Check the result
$stat = stat($path);
print_r(posix_getpwuid($stat['uid']));

?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

Array
(
    [name] => root
    [passwd] => x
    [uid] => 0
    [gid] => 0
    [gecos] => root
    [dir] => /root
    [shell] => /bin/bash
)
                

메모

참고: 검사할 파일은 서버의 파일 시스템을 통해 액세스할 수 있어야 하므로 이 함수는 원격 파일에서 작동하지 않습니다.

참고: Windows에서 이 함수는 일반 파일에 적용될 때 자동으로 실패합니다.


기타