日期:2014-05-17  浏览次数:20594 次

为何fwrite以后,fread不出来东西呢。
$file = 'test.txt';
$fileHandle = fopen($file,'w+');
fwrite($fileHandle, 'Newly inserted text');
$fileContents = fread($fileHandle, filesize($file));
echo $fileContents;
fclose($fileHandle);

The manual says that if the w+ option is specified then the file is opened for reading and writing. From what I understand this means that I should be able to read from the file after writing to it. But the code above displays nothing after writing to the file. The file is chmodded 777.  Can someone please explain to me why this is so :D

同问,为啥呢。
以w+模式打开,应该是可读,
可为何fwrite以后,fread不出来东西呢。

------解决方案--------------------
还真没试过这样,但可以猜想一下
1.指针问题
2.IO问题

想想写完之后指针在哪?如果在文件开头,第二次写入不是写到第一次前面了?
文件IO一般都涉及缓冲,两次操作中间无间断总会有想象不到的问题……