If chown is filled with a variable ( chown ("myfile", $uid) the uid will be looked up through pwget_uid.
So if you need to set a non existing uid use inval($uid).(PHP 4, PHP 5, PHP 7, PHP 8)
chown — ファイルの所有者を変更する
ファイルfilenameの所有者を(名前または番号で指定した)
ユーザーuserに変更しようと試みます。
スーパーユーザーのみがファイルの所有者を変更できます。
filenameファイルへのパス。
userユーザー名あるいはユーザー番号。
例1 シンプルな chown() の例
<?php
// 使用するファイル名とユーザー名
$file_name= "foo.php";
$path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
$user_name = "root";
// ユーザーを設定します
chown($path, $user_name);
// 結果を確認します
$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 で通常ファイルに対してこの関数を実行すると、静かに失敗します。
If chown is filled with a variable ( chown ("myfile", $uid) the uid will be looked up through pwget_uid.
So if you need to set a non existing uid use inval($uid).It may be worth making explicitly clear that, while the shell's `chown` command allows both user and group to be set in one system call like this `chown username:groupname filename`, PHP's version unfortunately does not:
<?php
// This will not work.
chown($filename, 'username:groupname');
// You have to use two separate calls.
chown($filename, 'username');
chgrp($filename, 'groupname');
?>