Creating & writing to a file (with permission 755) from PHP fails as PHP runs as 'nobody' and target file owner is another user

て烟熏妆下的殇ゞ 提交于 2019-12-12 02:03:43

问题


I am writing a PHP code that creates another PHP file with fopen and writes to it. It runs on most shared environments without any problem but in some old servers and customized servers the code fails to create file and write to it even though the folder permission is 755 as the PHP runs under the account 'nobody' and the folder owner is another user.

In shared servers the folder owner and the PHP both runs under same user and so there are no permission issues.

Can anyone help me out here with a solution please.....

Thank you All...

EDIT: This problem might have bugged many others including packages like Joomla, Drupa, etc. How do they get around this problem? Can anyone explain please. Thank you.


回答1:


If PHP runs as user 'nobody', but the folder you're trying to write in belongs to a different user, the only way to have write rights to that folder would be if 'nobody' is in the same group, of if the folder has permissions 777 (write rights for everyone).




回答2:


There is no direct solution to this problem. So the only solution was to show the user a relevant message and ask them to copy the files manually...



来源:https://stackoverflow.com/questions/6846549/creating-writing-to-a-file-with-permission-755-from-php-fails-as-php-runs-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!