开发者

random image name for an image

开发者 https://www.devze.com 2023-03-02 11:25 出处:网络
I have uploaded the image to specified directory. Now I want to store image with a diff开发者_C百科erent name using the \'upload\' library.How to accomplish this?Hash a random set of information (time

I have uploaded the image to specified directory. Now I want to store image with a diff开发者_C百科erent name using the 'upload' library.How to accomplish this?


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.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消