What you are saying here is that after the file has been uploaded by the code you posted, values are then stored into a database and then the error is triggered. So the loading into the database and the error being triggered happens below the code you posted and so I have no idea what you have done in that code because you haven’t posted it.
Under what conditions would a previous statement be called? Unless it was looped (it is not). The contents of the function doesn’t matter in this case, I can’t imagine a condition where the contents revisits the unless it includes the page (from which it is initially called from!)
The issue turned out to be caused by a race condition from when a file_exist() function and the move_uploaded_file() function is called. file_exist() is, from my understanding, time intensive. I tried to use clearstatcache() to no avail either (but wasn’t sure on where it’s application would have been best placed). Curiously, even applying an adequate sleep condition didn’t work.