LAST_INSERT_ID(). This function returns the AUTO_INCREMENT value of the last row that was inserted into a table with an AUTO_INCREMENT column.
How you might modify your process:
1. Insert Data
2. Get Last Inserted ID
3. Update File Name
I hope this will help you.