以下代码是我编写的PHP Web服务的一部分.它需要一些上传的Base64数据,对其进行解码,然后将其附加到文件中.一切正常.
问题是,当我在追加操作后读取文件大小时,我得到文件在追加操作之前的大小.
$fileOut = fopen($filepath.$filename, "ab")
fwrite($fileOut, base64_decode($data));
fflush($fileOut);
fclose($fileOut);
$newSize = filesize($filepath.$filename); // gives old file size
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
系统是:
根据PHP手册:
缓存此函数的结果.有关更多详细信息,请参阅clearstatcache().
http://us2.php.net/manual/en/function.filesize.php
基本上,您必须在文件操作后清除stat缓存:
$fileOut = fopen($filepath.$filename, "ab")
fwrite($fileOut, base64_decode($data));
fflush($fileOut);
fclose($fileOut);
clearstatcache();
$newSize = filesize($filepath.$filename);
Run Code Online (Sandbox Code Playgroud)