downloadTemp2014 2012-09-22 02:26
浏览 15
已采纳

PHP没有写入文件

I'm making a registration form, but can't seem to write to text file. In this code, I'm putting a person's real name in their file in acc/pplid/[name].txt The file isn't writing at all - the echo doesn't output anything. I'm running off of Microsoft Webmatrix on my computer. Thanks in advance!

        $irlname = $_POST["irlname"];
        $name = $_POST["username"];
        $email = $_POST["email"];
        $password = $_POST["password"];
        $name = htmlentities($name);

        echo $name;
        file_put_contents("acc/pplid/".name.".txt", $irlname);
        echo file_get_contents("acc/pplid/".$name.".txt");
  • 写回答

1条回答 默认 最新

  • dtrovwl75780 2012-09-22 02:29
    关注
    file_put_contents("acc/pplid/".name.".txt", $irlname);
    

    Should be

    file_put_contents("acc/pplid/".$name.".txt", $irlname);
    

    unless name is defined else where, otherwise I'd say check the write permissions. Check the status of the folder with file_exists or is_dir prior to file_put_contents.

    Example

    if(is_dir("acc/pplid") && is_writable("acc/pplid")){
        file_put_contents("acc/pplid/".$name.".txt", $irlname);
    } else echo "A problem with the folder occurred";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看