chown() function in PHP

PHPProgrammingServer Side Programming

The chown() function changes the file owner. Set a new owner for any file. This function won’t work for remote files.

Syntax

chown($file_path, $user );

Parameters

  • file_path − Set the path of file or directory to be checked. Required.

  • user − Set the new owner name or id.

Return

The chown() method returns.

  • True, on success
  • False, on failure

Example

The following is an example that set new owner for file “demo.txt”.

<?php
   // set new owner
   $file_path = "demo.php";
   $user = "jack";
   chown($file_path, $user);
?>

Let us see another example, wherein a new user is set for file “new.txt”.

Example

<?php
   // set new owner
   chown("new.txt","amit");
?>
raja
Published on 03-Oct-2018 11:58:51
Advertisements