我正在为我的项目尝试fopen
。它在 Ubuntu 上运行,带有 CodeIgniter PHP 框架。结果是这样的:
A PHP Error was encountered
Severity: Warning
Message: fopen(testFile.txt): failed to open stream: Permission denied
Filename: controllers/home.php
Line Number: 10
can't open file
顺便说一句,这是我在 Controller 上的代码:
public function create_file(){
$ourFileName = 'testFile.txt';
$ourFileHandle = fopen($ourFileName, 'r') or die ("can't open file");
fclose($ourFileHandle);
}
我看了那段代码,我想应该有一个打开文件的路径,对吧?如果是,我应该把路径放在哪里?因为,我遵循了本教程中的这段代码:http://www.tizag.com/phpT/filecreate.php .
让我感到困惑的一件事是,没有文件 testFile.txt
而我想创建它,但是如何授予创建它的权限。因为终端会说 No such file or directory for the file
。我该怎么办?
我还尝试在 www
目录上运行 chmod
。但是,它仍然没有用。
希望有人能帮我解决这个问题。谢谢...
最佳答案
有两种方式:
1.) 通过此命令“sudo chmod -R 777/var/www”将 chmod www 目录更改为 777。 这将递归地向所有子文件夹和文件授予权限。
2.) 如果您在第一步之后创建任何新文件夹(或 www 目录中的项目),请按照上述操作:
=> Right click on your current project folder
=> Scroll to Properties
=> Scroll to permissions
=> Add permission for "Create and Delete files" for owner, group, others.
=> Now click on "Change permission for enclosed files"
=> Give appropriate permissions for files and folders there.
全部完成。现在 fopen() 不应该发出警告。
关于php - fopen 权限被拒绝,Ubuntu,CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23756052/