The fileowner() function returns the user ID (owner) of the specified file.
PHP fileowner() Function has the following syntax.
fileowner(filename)
Parameter | Is Required | Description |
filename | Required. | File to check |
This function returns the user ID on success or FALSE on failure.
Use posix_getpwuid() to convert the user ID to a user name.
The result of this function are cached. Use clearstatcache() to clear the cache.
This function doesn't produce meaningful results on Windows systems.
To read the owner of a file, use the fileowner() function, which takes a filename and returns the ID of the file's owner.
<?PHP
$owner = fileowner("test.txt");
if ($owner != 0) {
print "Warning: /etc/passwd isn't owned by root!";
}
echo fileowner("test.txt");
?>
The code above generates the following result.
The following code shows how to get file owner.
<?php
$filename = 'index.php';
print_r(posix_getpwuid(fileowner($filename)));
?>