php Unique filename when uploading

后端 未结 5 1589
生来不讨喜
生来不讨喜 2020-12-11 04:14

I\'ve a submit discussion form with image upload in my website. Now, I want to upload a unique file name when the user submits their image so that I can show the result of a

5条回答
  •  一生所求
    2020-12-11 04:27

    You could use a timestamp in the date, that way you won't get the same filename/time twice.

    Not certain exactly what your code looks like but you could do something like this:

    $filename = uniqid() . $orig_filename;
    

    Read this documentation on the PHP docs about uniqid for more information. It uses the datetime to output a unique identifier string.

提交回复
热议问题