PHP chown() Function

PHP chown Function


Definition :

The chown() function in PHP is an inbuilt function.The PHP chown() function attempts to change the owner of the specified file. Only the superuser may change the owner of a file.

Syntax

  chown(fileowner)

Parameter
Parameter Description
file Required. Specifies the path to the file to change owner for
owner Required. Specifies the new owner. Can be a user name or a user ID.

Errors And Exception:

  1. The chown() function in PHP doesn’t works for remote files.It only works on files which are accessible by the server’s filesystem.
  2. 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.
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 change its owner.

Output :

Array
(
    [name] => root
    [passwd] => x
    [uid] => 0
    [gid] => 0
    [gecos] => root
    [dir] => /root
    [shell] => /bin/bash
)