Best method to generate unique filenames when uploading files PHP

Adamski picture Adamski · Dec 7, 2010 · Viewed 63.9k times · Source

Can any one suggest the best practice to generate unique file names for file uploads to avoid duplicate Entries?

Thanks In Advance.

Answer

ryudice picture ryudice · Dec 7, 2010

I usually either create a UID using uniqid() function for the filename or create a folder with the name of the username who is uploading the file and leave the original filename. The disadvantage of the first one is that you will have to save the original filename somewhere to show to the user.