chown

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

chown改變文件的所有者

說明

chown(string $filename, mixed $user): bool

嘗試將文件 filename 的所有者改成用戶 user(由用戶名或用戶 ID 指定)。 只有超級用戶可以改變文件的所有者。

參數(shù)

filename

文件路徑。

user

用戶名或數(shù)字。

返回值

成功時返回 true, 或者在失敗時返回 false

范例

示例 #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
)

注釋

注意: 此函數(shù)不能作用于遠程文件,被檢查的文件必須是可通過服務器的文件系統(tǒng)訪問的。

注意: 在 Windows 上對普通文件使用此函數(shù)會靜默失敗。

參見