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!

Alex
  • 1
  • 2

1 Answers1

0

After further investigating, I discovered the reason why some of my images were disappearing: the function file_exists() caches the result.

When looping through the same files many times, if the file did not exist to start for, then file_exists() would return false and a blank file would be created.

If this same file was used again and the result "false" was cached, then the previous image would be destroyed and a new blank file used.

To prevent this, I inserted clearstatcache(); at the start of very loop. This solved my problems!

I am changing the question title to better represent this situation.

Alex
  • 1
  • 2