The chown() function changes the owner of the specified file.
PHP chown() Function has the following syntax.
chown(file,owner)
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to check |
owner | Required. | New owner. Can be a user name or a user ID. |
PHP chown() Function returns TRUE on success and FALSE on failure.
chown() attempts to change the file to be owned by the user. On success, true is returned; otherwise, false.
The second parameter can either be a username or a user ID number.
<?PHP
if (chown("myfile.txt", "tom")) {
print "File owner changed.\n";
} else {
print "File ownership change failed!\n";
}
chown("test.txt","Jack");
?>
The code above generates the following result.