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.
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.
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.
- How to get the function name inside a function in PHP ?
- PHP | min( ) Function
- PHP | Ds\Set xor() Function
- D3.js | d3.min() function
- PHP | max( ) Function
- PHP | Ds\Set add() Function
- p5.js | nfc() function
- p5.js | nfp() Function
- p5.js | nfs() Function
- p5.js | nf() Function
- p5.js | pan() Function
- D3.js | d3.map.set() Function
- D3.js | d3.rgb() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.