-2

Im working on a image hosting website, and to prevent "already exists" error, i md5 the images that are being uploaded, the problem is that the URL to that website is already quite long plus the whole MD5 hash makes it even longer, is there any way to make the URL shorter?

4

4 回答 4

1

不必使用md5字符串作为图像文件名。为保证图片的唯一性,可以尝试以下方案:

  • md5()用户上传的每张新图片
  • md5()值存储在数据库中
  • 下次用户上传图片时,检查该项目是否已存在于您的数据库中
  • 如果存在,则阻止用户上传图像。否则,继续。
  • 重复
于 2013-09-12T17:19:21.580 回答
0

您可以在图像托管服务器上保留与哈希值映射的 id。您可以将此映射存储在 redis 或 mysql 中,因为它们都是持久性数据库。

于 2013-09-12T17:18:53.250 回答
0

您可以在上传时使用图像名称和时间,使其唯一但更短。像这样使用

$img_name = $uploaded_name.time().$file_ext;

因此,名称将更短但唯一。

于 2013-09-12T17:22:28.693 回答
0

只需使用 unix 时间戳来确保始终使用新的唯一文件名,并且保持长度也更短。

于 2014-06-22T16:33:54.550 回答