PHP chown() Function

Definition

The chown() function changes the owner of the specified file.

Syntax

PHP chown() Function has the following syntax.

chown(file,owner)

Parameter

ParameterIs RequiredDescription
fileRequired.File to check
ownerRequired.New owner. Can be a user name or a user ID.

Return

PHP chown() Function returns TRUE on success and FALSE on failure.

Example

chown() attempts to change the file to be owned by the user. On success, true is returned; otherwise, false.

The second parameter can either be a username or a user ID number.


<?PHP//  ww w.  j a  v a  2s .c o m
      if (chown("myfile.txt", "tom")) {
             print "File owner changed.\n";
      } else {
            print "File ownership change failed!\n";
      }
      
      chown("test.txt","Jack");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions