PHP Tutorial - 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
      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.