Saturday, December 13, 2025
HomeLanguagesPHP fileowner() Function

PHP fileowner() Function

The fileowner() is an inbuilt function in PHP that returns the details for the file owner.

Syntax:

fileowner(string $filename): int|false

Parameters: This function accepts a single parameter:

  • filename: This parameter specifies the file path for the specific file.

Name of the file.

Return Value: The user id of the owner will be returned by this function in case of true, otherwise, false on failure. The user id will be returned in numerical format. The posix_getpwuid() function will be used in order to resolve it to a username.

Error: An E_WARNING will be emitted, upon failure.

Example 1: The following code demonstrates the fileowner() function.

PHP




<?php
   $filename = "text.txt" ;
   print_r(posix_getpwuid(fileowner($filename)));
?>


Output:

Array
(
   [name] => dachman
   [passwd] => x
   [uid] => 1000
   [gid] => 1000
   [gecos] => dachman,,,
   [dir] => /home/dachman
    => /usr/bin/zsh
)
 

Example 2: The following code demonstrates the fileowner() function.

PHP




<?php
   $filename = "text.txt" ;
   print_r(fileowner($filename));
?>


Output:

1000

Reference: https://www.php.net/manual/en/function.fileowner.php

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7200 POSTS0 COMMENTS
Thapelo Manthata
6897 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS