chown

bool chown(string file, mixed user) 

Changes the ownership of a file.

Returns:

TRUE on success; FALSE on error

Description:

chown() changes the ownership of the specified file. Since this function on nearly all UNIX systems is restricted to being run by the superuser, it won’t operate correctly when PHP is run as a module (unless you run httpd as root). This function always returns TRUE on Win32 platforms.

Note:

If safe mode is enabled, chown() can only change the ownership of files that are owned by the user running the command. In most cases, this is the user that the web server runs as.

Example:

Change a file’s ownership to “user”
$file = "test_file"; 

if (! chown ($file, "user")) {
    echo ("Unable to change file ownership"); 
} 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.