PHP chown( ) Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The chown() function in PHP is an inbuilt function which is used to change the owner of the specified file. It returns true on success and false on failure. Only the superuser has the right to change the owner of a file. Syntax: bool chown ( $filename, $user ) Parameters: The chown() function in PHP accepts two parameters which are filename and user. $filename: It specifies the file whose owner you want to change. $user: It specifies the new owner. It can be a username or an user id. Return Value: The chown() function returns true on success and false on failure. Errors And Exception: The chown() function in PHP doesn't works for remote files.It only works on files which are accessible by the server's filesystem. PHP checks whether the files or directories which are being operated have the same owner as the script that is being executed or not when safe mode is enabled. Examples: Input : chown("gfg.txt", "shubrodeep") Output : true Input : $path = "/user01/Desktop/geeksforgeeks/gfg.php"; $user_name = "root"; chown($path, $user_name); Output : true Below programs illustrate the chown() function. Program 1: php <?php // Sets shubrodeep as owner chown("gfg.txt", "shubrodeep"); ?> Output: true Program 2: php <?php // Sets root as owner of the file "gfg.php" $path = "/user01/Desktop/geeksforgeeks/gfg.php"; $user_name = "root"; chown($path, $user_name); ?> Output: true Reference: https://www.php.net/manual/en/function.chown.php Comment S Shubrodeep Banerjee Follow 0 Improve S Shubrodeep Banerjee Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-file-handling Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like