简体   繁体   English

如何测试PHP中的文件写入是否成功?

[英]How can i test if a file write has succeeded in PHP?

Is there any way to test if writing to a file was successfully accomplished? 有没有办法测试写入文件是否成功完成? I need a method to obtain the end of time of a writing operation. 我需要一种方法来获得写操作的结束时间。 If so to trigger a callback function. 如果是这样则触发回调函数。

fwrite() returns the number of bytes written, or FALSE on error. fwrite()返回写入的字节数,或者出错时返回FALSE。

Check whether fwrite() returns false and you'll know that the write succeeded. 检查fwrite()是否返回false并且您将知道写入成功。 Be careful to use the === comparison operator instead of the == operator when checking if the returned value is false. 在检查返回值是否为false时,请小心使用===比较运算符而不是==运算符。

You can use filemtime() to get the last modification time of a file. 您可以使用filemtime()来获取文件的最后修改时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM