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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序