I'm trying to handle file uploads and now I face a dilemma. I have two options that I actually think about using when handling file name:
Option 1:
move_uploaded_file($_FILES['pdf']['tmp_name'], sprintf('./uploads/%s.%s', sha1_file($_FILES['pdf']['tmp_name']),$ext
Option 2:
move_uploaded_file($_FILES['pdf']['tmp_name'], sprintf('./uploads/%s.%s', "name_$date", $ext
First will generate hash with sha1_file which doesn't look pretty (and I would like to get that uploaded file name from DB and show it on page) but prevents multiple same file uploads.
Second gets a nice looking file name but doesn't prevent duplicates (file_exists
seems to recognize duplicate but I couldn't stop move_upload_file
)
What would you suggest me to do to get nice file name without file upload duplicates?