0

I edited the entire question to better represent the answer.

I had a for loop which would access and edit image files. Within the loop a file_exists() check was made. If the image file did not exist a blank one would be created.

What was happening was that even after the file was created, the file_exists() would continue returning false and creating new blank files (overwriting the previous operations).

This happens because file_exists() and some other file functions caches the result. To prevent this, use clearstatcache(); before using these functions if you expect the result to have changed and are checking the same file!

4

1 回答 1

0

经过进一步调查,我发现了我的一些图像消失的原因:函数 file_exists() 缓存了结果。

当多次循环遍历相同的文件时,如果文件不存在以启动,则 file_exists() 将返回 false 并创建一个空白文件。

如果再次使用相同的文件并且缓存了结果“false”,则先前的图像将被破坏并使用新的空白文件。

为了防止这种情况,我插入了 clearstatcache(); 在非常循环的开始。这解决了我的问题!

我正在更改问题标题以更好地代表这种情况。

于 2014-10-07T15:34:29.377 回答