Hàm chown() trong PHP

Hàm chown() sẽ thay đổi chủ sở hữu của file.

Cú pháp

Cú phápchown( $filename, $user);

Trong đó:

  • $filename là đường dẫn tới file.
  • $user là tên user, chủ sở hữu mới của file.

Kết quả trả về

Hàm sẽ trả về True nếu thực hiện thành công và trả về False nếu thất bại.

Bài viết này được đăng tại [kiso.vn]

Ví dụ

Đây là ví dụ về hàm chown() mình lấy từ trang chủ php.net:

// 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
)

Tham khảo: php.net