我正在建立一个网站,以轻松地查看数百万张照片(每张上传的图像各有3张缩略图),我需要找到存储所有这些图像的最佳方法。
我搜索并找到了存储为散列的图像的示例...例如...
如果我上传coolparty.jpg,我的脚本会将其转换为Md5哈希值,结果是。
dcehwd8y4fcf42wduasdha.jpg
并存储在
/dc/eh/wd/dcehwd8y4fcf42wduasdha.jpg
中但是对于3个缩略图,我不知道如何存储它们
问题..
最佳答案
我如何使用文件夹结构:
$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