下面的代码检查目录'dat';如果它不存在,它会创建一个。这部分工作得很好;我需要的是让它将文件写入 AJAX 可以从中读取它的所述目录。
这是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);
}
这是 AJAX;我在这里不需要像上面那样多的帮助,但是如果您为下面的 AJAX 提供帮助,我不会抱怨,主要是让它从"dat"目录中的文件读取......
xhr.open("GET","chatlog<?php /*stamps the chatlog file with date (numerical day only)*/ echo date("d");?>.txt",true);
你的PHP脚本在www中运行,然后,你的文件在那里创建。
如果要在目录 www/dat 中创建文件,只需更改此行
$file = "chatlog". date('d'). ".txt";
对于这个
$file = 'dat'chatlog'. date('d'). '.txt';