我提供此目录&文件:
$path = $_POST['q2Path'];
$file = "test.txt";
// q2Path == "C:\Users\micah\Desktop\only_dir_named_this"
代码运行此块:
$write_str = "TEST TEST TEST";
$fh = fopen($file, 'a') or die("can't open: $path\\$file");
$chars = fwrite($fh, $write_str) or die("can't write to: $path\\$file");
fclose($fh) or die("can't close: $path\\$file");
echo "<pre>> Appended $chars characters to: $path\\$file</pre>";
这是浏览器输出:
将14个字符附加到:C:\ Users \ micah \ Desktop \ only_dir_named_this \ test.txt
最后,文件为空,“上次修改”的时间戳没有改变。我不确定是什么。我在Win7上使用ZendServer。也许有一个需要调整的php.ini设置?我从来没有遇到过简单文件写的问题......
答案 0 :(得分:1)
你写$path\\$file
,但你做fopen($file, 'a')
应该是
$fh = fopen($path . DIRECTORY_SEPARATOR . $file, 'a') or die("can't open: $path\\$file");