使用 PHP 在没有正确权限的情况下写入文件

发布于 2025-01-08 14:08:17 字数 144 浏览 2 评论 0原文

我正在尝试为我的 PHP(CodeIgniter) 应用程序创建一个安装脚本,我需要将从用户那里获得的数据库信息写入 CI 数据库配置文件。当然,我这样做遇到了权限问题,因为配置目录没有写权限。所以我的问题是,如果不让安装我的应用程序的用户自己管理文件夹权限,这将如何实现。

I'm trying to create a installation script for my PHP(CodeIgniter) app and i need to write database info that i get from user to CI database conf file. Of course i run into permissions problem doing so because config directory doesn't have write permission. So my question is how would this be possible without making user who installs my app to manage folder permissions him/herself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七颜 2025-01-15 14:08:17

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

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

They have to have access to the webserver's folder read/write options on their end - many hosts don't let you do this through FTP access so you can't even do a direct solution using that - they may have to go through the Control Panel system to do this type of task.

There's no "Run this script and it'll change folder permissions" code out there - the end user will have to be savvy enough to know how to do this.

掐死时间 2025-01-15 14:08:17

您可以尝试这样的操作:

- 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

You could try something like this:

- 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)

You can use chmod to change the folder/file permission:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文