This is definitely one of the trickier objectives that I have encountered in a php app. You could do some sort of hybrid solution where you have a db table with an auto increment and add to this table before uploading the file, then just use the last inserted id stored in a session variable to append to the file name. Even this would be a little complicated but I think it is an easier approach than coming up with your own method of creating auto incrementing unique ids for the filenames.