Reputation: 5732
How can I keep the file permission and the owner when I copy a file with PHP?
Code that copies file:
$source = CSS . 'customers' . DS . 'source.css';
$destination = CSS . 'customers' . DS . 'destination.css';
if(!@copy($source, $destination)) {
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
Output:
-rwxrwxrwx 1 myuser admin 7145 11 Nov 20:02 source.css
-rw-r--r-- 1 daemon admin 7145 19 Nov 16:27 destination.css
Upvotes: 0
Views: 2164
Reputation: 1601
Only admin/root can change owner of a file.
What you can do is set the file permissions to be readable by group or all users.
exec( 'chmod 664 ' . $filename ); // Group only
exec( 'chmod 666 ' . $filename ); // All users
Filename is the absolute filename with path or relative to scripts path!
Upvotes: 1