The concept for updating the file name is the same, but you will need to come up with the logic to generate the unique id values to use. You could use some random values that you store in a variable for this in php but how do you ensure that the value has not been used before? This is not an easy thing to deal with and will require some custom coding with logic to create a truly unique id to use.
I think having a table in your db with an auto incrementing column would be the best way to start with this.