I'm trying to save an image from a remote location to a local location. Currently when I save the file it's saving correctly, with the correct permissions (0755) with with the wrong owner / group. It's currently saving as group 'nobody' and owner 'nobody'. I need to save this as the username instead.
Here is my code that saves the image:
file_put_contents($filename, $content);
chgrp($filename, 'username');
chown($filename, 'username');
chmod($filename, 0755);
You cannot chown a file to another user, unless you're running as root. This is a security measure. A hostile user could trivially create/chown a bunch of files to a different user and consume that user's quota.