dsqbkh3630 2012-07-04 08:59
浏览 92
已采纳

使用php创建txt文件失败

I am trying to create a file and write a message in a folder called debug:

 function debug($report){
   $file="/debug/debug.txt";
   file_put_contents($file,$report,FILE_APPEND | LOCK_EX);
 }

The debug folder is in my root directory. But file fails to be created.. Why?

  • 写回答

3条回答 默认 最新

  • duanqi6274 2012-07-04 09:04
    关注

    This code will open all the permissions for the folder.

    chmod('PATH_TO_FOLDER',0777);
    

    Depending on what exactly you want to do with that folder, you might consider giving it slightly more limited permissions that allow only specific users to read/write to it.

    Here are some other examples taken from the PHP manual - http://php.net/manual/en/function.chmod.php

    <?php
    // Read and write for owner, nothing for everybody else
    chmod("/somedir/somefile", 0600);
    
    // Read and write for owner, read for everybody else
    chmod("/somedir/somefile", 0644);
    
    // Everything for owner, read and execute for others
    chmod("/somedir/somefile", 0755);
    
    // Everything for owner, read and execute for owner's group
    chmod("/somedir/somefile", 0750);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私