0

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?

Nisha haridas
  • 332
  • 1
  • 8
  • 22

4 Answers4

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.

1

Set encrypt_name to TRUE. This a feature of the File Uploading class.

stef
  • 26,771
  • 31
  • 105
  • 143
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
0

Generate unique, random filenames using uniqid() or (even better) generate UUIDs.

Community
  • 1
  • 1
Sander Marechal
  • 22,978
  • 13
  • 65
  • 96