chown() function in PHP


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");
?>

Updated on: 24-Jun-2020

185 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements