• PHP Video Tutorials

PHP - Function chown()



The chown() function can change the owner of a specified file.

Syntax

bool chown ( string filename, mixed user )

Attempts to change the owner of a file: filename to the user (specified by name or number), and only the superuser may change the owner of a file. This function returns true on success, otherwise false on failure.

Example

<?php
   // File name and username to use
   $file_name= "index.php";
   $path = "/PhpProject/backup: " . $file_name ;
   $user_name = "root";

   // Set the user
   chown($path, $user_name);
   print_r($path);
?>

Output

/PhpProject/backup: index.php
php_function_reference.htm
Advertisements