I have a script that I'm using in an admin control panel to allow users to easily change the write permissions on some configuration files, but I've got a little issue.
There are 2 main switches, one that allows the user to change the file to 'writable' => 0777 and one to 'protected' => 0444. This first works fine, however with the second, when I run it, no errors display and it acts as if it has successfully changed permissions,开发者_StackOverflow社区 but viewing in FTP shows that the file is in fact 0644, it seems it cannot change to 0444 successfully. Any ideas?
The account that is executing the PHP has to own the file before you can modify the permissions. "www-data" or "apache" are common user accounts.
Also making something senstive globally readable or writable is really bad idea. Its also a bad idea to make it executable. You probably want 400
and chmod 500
.
I think the approach is wrong, php will always need write permissions to be able to change anything in the future so a hard file-read-only-permission is not the way to go.
A solution would be a database table or another configuration file that keeps track of which files are locked an which files can be changed (and by whom....). You can then add php checks to see if a certain user can change a certain file.
精彩评论