我应该如何编写不应该被公众访问的文件?首先,如何写入 CI 根文件夹之外的文件?其次,为了能够写入文件,我需要将文件权限设置为 777,然后公众可以访问该权限。我应该如何处理这个?
问问题
241 次
1 回答
0
CI 文件助手将“帮助”您执行此操作:
$this->load->helper('file');
write_file('./path/to/file.php', $data);
文件的路径可以是相对路径或绝对路径,因此您可以将此文件写入系统上的任何位置(甚至在 CI 根文件夹上方 - 只要您有权写入该目录即可。
例如:
// CI Root folder is at /var/www/my_ci_project
// Directory to write to is at /var/www/tmp_files
$this->load->helper('file');
write_file('/var/www/tmp_files/file.php', $data);
至于权限,您只需要该文件是网络服务器用户可写的组:
// Everything for owner, read and execute for owner's group
chmod("/var/www/tmp_files/file.php", 0770);
于 2014-11-11T18:11:56.527 回答