我正在建立一个网站,以轻松地查看数百万张照片(每张上传的图像各有3张缩略图),我需要找到存储所有这些图像的最佳方法。

我搜索并找到了存储为散列的图像的示例...例如...

如果我上传coolparty.jpg,我的脚本会将其转换为Md5哈希值,结果是。

dcehwd8y4fcf42wduasdha.jpg

并存储在/dc/eh/wd/dcehwd8y4fcf42wduasdha.jpg
但是对于3个缩略图,我不知道如何存储它们

问题..
  • 这是存储这些图像的正确方法吗?
  • 我将如何存储缩略图?
  • 在PHP中,使用上述方法存储这些图像的示例代码是什么?
  • 最佳答案

    我如何使用文件夹结构:

  • 我正在上传照片,并按照您说的进行移动:
    $image = md5_file($_FILES['image']['tmp_name']);
    // you can add a random number to the file name just to make sure your images will be "unique"
    $image = md5(mt_rand().$image);
    $folder = $image[0]."/".$image[1]."/".$image[2]."/";
    
    // IMAGES_PATH is a constant stored in my global config
    define('IMAGES_PATH', '/path/to/my/images/');
    // coolparty = f3d40fc20a86e4bf8ab717a6166a02d4
    $folder = IMAGES_PATH.$folder.'f3d40fc20a86e4bf8ab717a6166a02d4.jpg';
    // thumbnail, I just append the t_ before image name
    $folder = IMAGES_PATH.$folder.'t_f3d40fc20a86e4bf8ab717a6166a02d4.jpg';
    // move_uploaded_file(), with thumbnail after process
    // also make sure you create the folders in mkdir() before you move them
    
  • 我相信
  • 是基本方法,当然,您可以将文件夹结构更改为更深的文件夹结构(如您所说),如果您将拥有数百万个图像,则可以使用2个字符。
  • 10-05 20:28
    查看更多