如何在上传到文件系统时避免使用相同的图像名称

I have a form whereby Users upload pictures as part of their registration process. But my issue is that, users that save the names of their image with the same name might cause some issues when they view the profile pictures. How can i make the picture name unique at the point of uploading to the filesystem..

Thanks.

If this helps

$t = uniqid();
$filename='user-'.$t;
echo $filename; // user-1335601088 (always a different name)

I would suggest using one of the following schemes:

  • make the filename a function of the username/userid
  • make the filename a random value
  • make the filename a function of the file content (e.g. an MD5 checksum)