chown in PHP

Syntax of chown in PHP

bool chown(string path, mixed user)

Changes ownership for the file path to the user named user. PHP must have appropriate privileges (generally, root for this function) for the function to operate. Returns true if the change was successful and false if not


// File name and username to use
$file_name= "foo.php";
$path = "/home/sites/" . $file_name ;
$user_name = "root";

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

// Check the result
$stat = stat($path);

    [name] => root
    [passwd] => x
    [uid] => 0
    [gid] => 0
    [gecos] => root
    [dir] => /root
     => /bin/bash

Leave a Comment