Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php fwrite()报告写入的字符,但它们';你不在那里_Php_Fwrite - Fatal编程技术网

php fwrite()报告写入的字符,但它们';你不在那里

php fwrite()报告写入的字符,但它们';你不在那里,php,fwrite,Php,Fwrite,我提供以下目录和文件: $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) o

我提供以下目录和文件:

$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>&gt; Appended $chars characters to: $path\\$file</pre>"; 
$write_str=“TEST”;
$fh=fopen($file,'a')或die(“无法打开:$path\\$file”);
$chars=fwrite($fh,$write_str)或die(“无法写入:$path\\$file”);
fclose($fh)或die(“无法关闭:$path\\$file”);
echo“将$chars字符附加到:$path\\$file”;
这是浏览器输出:

将14个字符附加到:C:\Users\micah\Desktop\only\u dir\u named\u this\test.txt


最后,文件是空的,“上次修改”的时间戳没有改变。我不知道发生了什么事。我正在Win7上使用ZendServer。也许有一个php.ini设置需要调整?我从来没有遇到过简单的文件写入问题…

您编写
$path\\$file
,但您确实编写了
fopen($file,'a')

应该是


如果试图写入不存在的文件,会发生什么情况?PHP脚本所在的目录中是否有test.txt?因为您没有指定路径,所以它可能正在写入该路径。这意味着它正在写入
test.txt
,但该文件与PHP脚本位于同一目录中。太棒了,谢谢。果然,目录中有大量的测试文件,对于我在过去30分钟内所做的每一次失败的页面刷新,都有一个字符串。
$fh = fopen($path . DIRECTORY_SEPARATOR . $file, 'a') or die("can't open: $path\\$file");