PHP Tutorial - PHP fileowner() Function






Definition

The fileowner() function returns the user ID (owner) of the specified file.

Syntax

PHP fileowner() Function has the following syntax.

fileowner(filename)

Parameter

ParameterIs RequiredDescription
filenameRequired.File to check

Return

This function returns the user ID on success or FALSE on failure.





Note

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.

Example

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.





Example 2

The following code shows how to get file owner.



<?php
$filename = 'index.php';
print_r(posix_getpwuid(fileowner($filename)));
?>