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 — Ändert den Eigentümer einer Datei
Ändert den Eigentümer der Datei filename
in Benutzer user. Nur der Superuser kann
den Eigentümer einer Datei ändern.
filenamePfad zur Zieldatei.
userEin Benutzername oder eine numerische Benutzer-ID.
Beispiel #1 Einfache chown()-Benutzung
<?php
// Datei- und Benutzernamen setzen
$file_name= "foo.php";
$path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
$user_name = "root";
// Benutzer setzen
chown($path, $user_name);
// Ergebnis prüfen
$stat = stat($path);
print_r(posix_getpwuid($stat['uid']));
?>Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
Array
(
[name] => root
[passwd] => x
[uid] => 0
[gid] => 0
[gecos] => root
[dir] => /root
[shell] => /bin/bash
)
Hinweis: Diese Funktion kann nicht mit entfernten Dateien arbeiten, da der Zugriff auf die Datei, die bearbeitet werden soll, über das Dateisystem des Servers möglich sein muss.
Hinweis: Unter Windows schlägt diese Funktion stillschweigend fehl, wenn sie auf eine reguläre Datei angewendet wird.
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');
?>