douyingmou1389 2014-05-20 09:34
浏览 147
已采纳

fopen Permission denied,Ubuntu,CodeIgniter

I was trying fopen for my project. Which running on Ubuntu with CodeIgniter PHP framework. The result was like this:

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

By the way, here are my code on Controller:

public function create_file(){
    $ourFileName = 'testFile.txt';
    $ourFileHandle = fopen($ourFileName, 'r') or die ("can't open file");
    fclose($ourFileHandle);
}

I looked at that code, and I thought that there is should be a path where I open the file, right? If yes, where should I put the path? Because, I followed this code from this tutorial: http://www.tizag.com/phpT/filecreate.php.

One thing that make me confuse is, there is no file testFile.txt and I wanna create it, but how to give the permission to create it. Because terminal will say No such file or directory for the file. What should I do?

I've also tried to run the chmod on www directory. But, it still didn't work. Hope anyone help me to handle this problem. Thank you...

  • 写回答

3条回答 默认 最新

  • doupeng2253 2014-05-20 09:42
    关注

    There are 2 ways :

    1.) chmod www directory to 777 by this command "sudo chmod -R 777 /var/www". This will give permissions recursively to all sub-folders and files.

    2.) If you create any new folders (or projects in www directory) in future after the 1st step , then follow above :

    => 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.
    

    All done. Now fopen() should not give that warning.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元