使用PHP写入没有正确权限的文件

时间:2012-02-23 11:57:16

标签: php file-writing

我正在尝试为我的PHP(CodeIgniter)应用程序创建安装脚本,我需要编写从用户到CI数据库conf文件的数据库信息。当然,由于配置目录没有写入权限,我遇到了权限问题。所以我的问题是,如果不让安装我的应用程序的用户自己管理文件夹权限,这将是多么可能。

2 个答案:

答案 0 :(得分:1)

他们必须能够访问网络服务器的文件夹读/写选项 - 许多主机不允许您通过FTP访问来执行此操作,因此您甚至无法使用它直接解决 - 他们可能必须去通过控制面板系统来完成这类任务。

没有“运行此脚本并且它将更改文件夹权限”代码 - 最终用户必须足够精明才能知道如何执行此操作。

答案 1 :(得分:0)

您可以尝试这样的事情:

- setup script checks permission on configuration files at startup
- if the files are not writeable, ask user to manually set permission manually (using FTP)
- after setup finishes the execution, use `chmod` command to make the files not writeable
- after the setup is completed, ask the user to delete the setup scripts for security reasons (so the setup is not run again by someone else)

您可以使用chmod更改文件夹/文件权限:

// Everything for owner, read and execute for others
chmod("/somedir/somefile", 0755);

http://php.net/manual/en/function.chmod.php