PHPs move_uploaded_file does not respect setgid

2019-09-05 16:02发布

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.

3条回答
Bombasti
2楼-- · 2019-09-05 16:14

I had this problem back in early '13 and fixed it by replacing move_uploaded_file with copy. I am not aware of the actual performance and memory impact, but it seems to be irrelevant.

查看更多
Anthone
3楼-- · 2019-09-05 16:20

You may or may not have access to the system call, but a system("cp") or even an explicit chgrp 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.

查看更多
手持菜刀,她持情操
4楼-- · 2019-09-05 16:33

Try PHP's built in rename instead of move_uploaded_file().

查看更多
登录 后发表回答