I am building a PHP application that lets users upload photos. To make it manageable, a folder shall have maximum of 5000 photos. Each uploaded photo will be assigned an ID in the database, and the photo will be renamed to the ID.
How do I check if a certain folder has 5000 photos? Should I check the ID of the last row in the photo table?
Folders shall be named incrementally. eg. folder_1
, folder_2
, etc.
My proposed steps:
- Retrieve last insert ID of photo table
- (Last_insert_ID + 1) % 5000 = Some_number (The folder number it should be saved in)
- Save photo to folder_some_number. If folder not exist, create new one.
Or is there a better way to do this?