I have uploaded the image to specified directory. Now I want to store image with a different name using the 'upload' library.How to accomplish this?
Asked
Active
Viewed 2,171 times
4 Answers
2
Hash a random set of information (time, filesize, etc) and check to see if the file exists. If it does, try again (will be at a different time, therefore, you will get a different hash). You can use this hash as the filename and store the relations in a database.
0
You can strore a value in database and append the name of the image with that value. for example if you are saving the details such as the name of the image in database, set a primary key as 'id'. and every time you add/upload an image increment that id and append that id with the name of the image. Say the id as 6 last time then increment it to 7 and append it as 7abc.jpg.

Varada
- 16,026
- 13
- 48
- 69
-
-1 Risk of collission here. For example, the first file I upload is `1abc.jpg` and the 11th file I upload is `abc.jpg`. – Sander Marechal May 04 '11 at 06:15
-
{table-pk}-filname.ext no collisions now. – Imran Naqvi May 04 '11 at 06:35
-
incase of the 11th file itshould be 11 as we are updating the database with the new count. So there will be no repetation of digit. – Varada May 04 '11 at 07:09
0
Generate unique, random filenames using uniqid()
or (even better) generate UUIDs.

Community
- 1
- 1

Sander Marechal
- 22,978
- 13
- 65
- 96