0

I've created my first site with an image uploading feature and this just crossed my mind. Is ['tmp_name'] in $_FILES a unique value like in uniqid()?

3 Answers 3

4

It's unique for the time being. As soon as you delete it (it should be deleted automatically when the script finishes) some file may and eventually will get the same name. PHP manual doesn't say that tmp_name is unique, so simplified answer is no, it isn't.

Sign up to request clarification or add additional context in comments.

Comments

1

It's unique in that you can never have two files with the same name at any given time. However since the files are temporary they will most likely be deleted shortly after their creation, so the filenames free up again.

2 Comments

However since the files are temporary they will most likely be deleted shortly after their creation - from the manual: The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
I was talking about temporary files in general, but thanks for the info :)
1

Yes, PHP generates this to uniquely name an uploaded file. You can't guarantee the file will stay around forever depending on where it's stored to. Often it's /var/tmp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.