How to Change File Ownership in PHP
- 1). Create a new text file with your favorite text editor. Paste the following PHP tags into it:
<?php
?>
All the code will go within these tags. - 2). Paste the following code to change the owner of the file:
$filename = "afile.txt";
$user_name = "root";
chown($filename, $user_name);
This changes the owner of the file "afile.txt" to the "root" user. Replace the file name and user name with the ones you would like to use. - 3). Save your script by hitting the "Ctrl" and "S" keys simultaneously.
Source...