Generally it is a very bad idea to create a file basing on the name received from the upload field. If the possibility of overwriting files with 'same names' is necessary, i'd create a DBM file with names of uploaded files as keys and names of files on the server as values. The names of files on server could be e.g. generated with
. And you can add any extra logic on the stage of creating new keys in DB.