dtdr84101 2013-01-04 18:46
浏览 15
已采纳

创建文本文件会引发错误

I am a php beginner.I want every time when the web page is open to create a file that does not exist. But every time when I run the program I have an error teling me that the file was not created. This is my code:

$ip=$_SERVER["REMOTE_ADDR"];
if(!isset($_COOKIE['firsttime'])){
  setcookie('firsttime', 'no');
  $myfile = 'file/form'.$ip.'.txt';
  if(file_exists($myfile) == FALSE){
    $fo = fopen($myfile, 'w');
    $code = '<form action = "" method = "post">';
    fwrite($fo, $code);
    fclose($fo);
  }else{
    unlink($myfile);
    $file = new File();
  }

}

where is my mistake?

  • 写回答

2条回答 默认 最新

  • donglao4370 2013-01-04 18:48
    关注
    $ourFileName = "testFile.txt";
    $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
    fclose($ourFileHandle);
    

    Do this to open a file, and it will create the file if it doesn't exist.

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

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题