PHP Function Reference

PHP fileowner() Function



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

Note: The results of this function are cached. Use clearstatcache() function to clear the cache.

Syntax

fileowner(filename)

Parameters

filename Required. Specify the path to the file to check.

Return Value

Returns the user ID of the owner of the file, or false on failure. The user ID is returned in numerical format. The posix_getpwuid() function can be used to convert it to a username.

Exceptions

Upon failure, an E_WARNING is thrown.

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to get the user ID of the owner of the file.

<?php
$filename = 'test.txt';

//getting the user ID
echo "user ID: ".fileowner($filename)."\n";

//getting the username
print_r(posix_getpwuid(fileowner($filename)));
?>

The output of the above code will be:

user ID: 33
Array
(
    [name] => www-data
    [passwd] => x
    [uid] => 33
    [gid] => 33
    [gecos] => www-data
    [dir] => 
    [shell] => /usr/sbin/nologin
)

❮ PHP Filesystem Reference