dsqbkh3630 2012-07-04 00: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 01: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部