成千上万的图像,我应该如何组织目录结构? (Linux) [英] Thousands of images, how should I organize the directory structure? (linux)

查看:87
本文介绍了成千上万的图像,我应该如何组织目录结构? (Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在由1and1.com托管的Linux服务器上,成千上万的用户上传了数千张图片(我相信他们使用的是CentOS,但不确定该版本).这是一个与语言无关的问题,但是,供您参考,我正在使用PHP.

I am getting thousands of pictures uploaded by thousands of users on my Linux server, which is hosted by 1and1.com (I believe they use CentOS, but am unsure of the version). This is a language agnostic question, however, for your reference, I am using PHP.

我的第一个想法是将它们全部转储到同一目录中,但是,我记得前一阵子,在一个目录中可以放多少个文件或目录是有限制的.

My first thought was to just dump them all in the same directory, however, I remember a little while ago, there was a limit to how many files or directories could be dropped in a directory.

我的第二个想法是根据用户的电子邮件地址对目录内的文件进行分区(因为无论如何,这都是我使用的用户名),但是我不想遇到目录中目录的限制. ...

My second thought was to partition the files inside directories based on the users email address (as it is what I am using for the user name anyhow) but I don't want to run into the limit for directories in a directory....

无论如何,对于来自user@domain.com的图像,我要这样做:

Anyhow, for images from user@domain.com, I was going to do this:

/images/domain.com/user/images...

这样做很聪明,如果成千上万的用户说"gmail",那么我什至可以像这样更深入

Is this smart to do, what if thousands of users have say 'gmail' perhaps I could even go deeper, like this

/images/domain.com/[first letter of user name]/user/images...

所以对于mike@gmail.com,它将是...

so for mike@gmail.com it would be...

/images/domain.com/m/mike/images...

这是一个不好的方法吗?其他人都在做什么?我也不想遇到太多目录的问题...

Is this a bad approach? What is everyone else doing? I don't want to run into problems with too many directories also...

相关:

  • How many files in a directory is too many?
  • Optimum web folder structure for ~250,000 images
  • How to store images in your filesystem
  • Tips for managing a large number of files?

推荐答案

我将执行以下操作:

  1. 对每张图像进行MD5哈希处理.
  2. 在要跟踪这些内容的数据库中写入MD5哈希值.
  3. 将它们存储在目录结构中,在其中您将MD5哈希十六进制字符串的前两个字节用作目录名.因此,如果哈希为"abcdef1234567890",则将其存储为"a/b/abcdef1234567890".

使用哈希还可以让您合并多次上传的同一张图片.

Using a hash also lets you merge the same image uploaded multiple times.

这篇关于成千上万的图像,我应该如何组织目录结构? (Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆