I've moving completed uploads with the function move_uploaded_file
. I have noticed this does not respect the target directory's setgid bit and has what the file originally had. (I learnt this is Linux behaviour).
What is a good solution to the problem? I thought about loading the file into PHP and resaving it, but the files can be quite big 50MB+ which means more memory usage for PHP.
I had this problem back in early '13 and fixed it by replacing
move_uploaded_file
withcopy
. I am not aware of the actual performance and memory impact, but it seems to be irrelevant.You may or may not have access to the
system
call, but asystem("cp")
or even an explicitchgrp
might do what you want, as far as obeying the setgid bit. You might need to do some sleuthing to get the existing group if it varies from target directory to target directory.Try PHP's built in rename instead of move_uploaded_file().