PHP chmod() 不会将权限更改为 0444
我有一个在管理控制面板中使用的脚本,允许用户轻松更改某些配置文件的写入权限,但我遇到了一个小问题。
有 2 个主要开关,其中一个允许用户将文件更改为“可写”=>第0777章 1 0444。第一个工作正常,但是第二个,当我运行它时,没有显示错误,它的行为就好像它已成功更改权限,但在 FTP 中查看显示该文件实际上是 0644,似乎无法更改为0444 成功。有什么想法吗?
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, but viewing in FTP shows that the file is in fact 0644, it seems it cannot change to 0444 successfully. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行 PHP 的帐户必须拥有该文件,然后才能修改权限。 “www-data”或“apache”是常见用户帐户。
另外,让一些敏感的东西全局可读或可写确实是个坏主意。使其可执行也是一个坏主意。您可能需要
400
和 chmod500
。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 chmod500
.我认为这种方法是错误的,php 总是需要写入权限才能在将来更改任何内容,因此硬文件只读权限不是可行的方法。
解决方案是使用数据库表或另一个配置文件来跟踪哪些文件被锁定以及哪些文件可以更改(以及由谁......)。然后,您可以添加 php 检查来查看某个用户是否可以更改某个文件。
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.