dony39517 2014-12-14 10:23
浏览 32
已采纳

php在目录中创建文件

The below code checks for a directory 'dat'; if it ins't there, it creates one. That part works just fine; what I need is for it to write a file to said directory where AJAX can read it from.

Here's the php...

//checks for 'dat' directory; if false, creates it, if true, does nothing.
$dir = 'c:\wamp\www\dat';
if(file_exists($dir)){
return;
}
else{
mkdir ('C:\wamp\www\dat',0700);
}
//writes chats to file
$data = fopen($dir. "/chatlog". date('d'). '.txt', 'a+');
fwrite($data, $speak);
fclose($data);
}

And here's the AJAX; I don't need as much help here as I do above, but I won't complain if you provide the help for the AJAX below, mainly in getting it to read from the file within the 'dat' directory...

xhr.open("GET","chatlog<?php /*stamps the chatlog file with date (numerical day only)*/ echo     date("d");?>.txt",true);
  • 写回答

1条回答 默认 最新

  • dongxiaoxing3058 2014-12-15 14:14
    关注

    Your PHP script is running inside www, then, your file you be created there.

    If you want to create the file inside the directory www/dat, just change this line

    $file = "chatlog". date('d'). ".txt";
    

    for this one

    $file = 'dat\chatlog'. date('d'). '.txt';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部