知道图片上传网站如何保存图片吗?

发布于 2024-10-05 10:13:03 字数 575 浏览 0 评论 0原文

它更多的是一个与架构相关的问题,如果我在错误的堆栈中询问,抱歉。

他们把它们放在一大堆文件夹里吗? 喜欢

$uid.$md5(随机).$name 保存在一个中 文件夹

folder/5231.124wdadace123214.arandomname.jpg
folder/42.15125dawdaowdaw232.arandom2name.png
folder/etc

$uid/$md5(随机).$name

5231(uid)/12421adwawda2321.arandomname.jpg
42/15125awdawdwadwa232.arandom2name.png
etc/2323awdwadwadaw.logo.png

我认为第二个更好?
因为在 Windows 中我在一个文件夹中有很多图片
是的,打开它需要时间。

你们知道他们如何保存文件吗?

its more to a architecture related question, sorry if i ask in the wrong stack.

do they put them in a large pile im a folder ?
like

$uid.$md5(random).$name save in one
folder

folder/5231.124wdadace123214.arandomname.jpg
folder/42.15125dawdaowdaw232.arandom2name.png
folder/etc

or

$uid/$md5(random).$name

5231(uid)/12421adwawda2321.arandomname.jpg
42/15125awdawdwadwa232.arandom2name.png
etc/2323awdwadwadaw.logo.png

what im thinking here is the second one is better?
because at windows i have a lot of pics in one folder
and yes it takes time to open it.

do you guys have any idea how they keep the files ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

懒的傷心 2024-10-12 10:13:03

我为我的网站编写了一个函数,将用户 ID 转换为两级子目录层次结构,每级子目录数限制为 1000 个。

function get_image_dir($gid) {
    $d = str_split(str_pad($gid, 6, "0", STR_PAD_LEFT), 3);
    $wdir = "/images/members/" . $d[0] . "/" . $d[1] . "/" . $gid;
    return $wdir;
}

(实际上,我添加了第三个级别,其中包含原始用户 ID,以处理 1,000,000 的翻转。

/images/members/000/001/1
/images/members/000/002/2
...
/images/members/999/999/999999
/images/members/000/000/1000000
/images/members/000/001/1000001

在这些子目录中,我根据

  1. 专辑(由成员组织)
  2. 进一步隔离各种大小调整(针对不同的大小)
    网站上的

最终结构看起来像

/images/members/000/001/1/album1/original
/images/members/000/001/1/album1/50x50
/images/members/000/001/1/album1/75x75
/images/members/000/001/1/album1/400x300

函数中的 str_split(str_pad()) 可能不是最佳的,但目前它可以工作。

I wrote a function for my sites that converts user ids into a two level subdirectory hierarchy that limits subdirectories to 1000 at each level.

function get_image_dir($gid) {
    $d = str_split(str_pad($gid, 6, "0", STR_PAD_LEFT), 3);
    $wdir = "/images/members/" . $d[0] . "/" . $d[1] . "/" . $gid;
    return $wdir;
}

(I actually add a third level with the raw user id to handle the rollover at 1,000,000.

/images/members/000/001/1
/images/members/000/002/2
...
/images/members/999/999/999999
/images/members/000/000/1000000
/images/members/000/001/1000001

Within those subdirectories, I further segregate based on

  1. albums (organized by members)
  2. various resizings (for different
    places on the site

Final structure looks something like

/images/members/000/001/1/album1/original
/images/members/000/001/1/album1/50x50
/images/members/000/001/1/album1/75x75
/images/members/000/001/1/album1/400x300

The str_split(str_pad()) in the function probably isn't optimal, but for now it works.

剑心龙吟 2024-10-12 10:13:03

这主要取决于文件系统。对于像 NTFS 或 ext3 这样的现代文件系统,在同一目录中保存大量文件不是问题,但一些较旧的文件系统无法处理它。

然而,根据某种方案将文件分区到子目录中仍然是一个好主意,只是为了让它们可以使用各种工具(这些工具可能有自己的庞大目录问题)(例如备份)进行管理。顺便说一句,在 Windows 资源管理器中打开目录也属于这种情况。

This depends mainly on the filesystem. For a modern filesystem like NTFS or ext3, keeping huge numbers of files in the same directory is not a problem, but some older filesystems could not handle it.

However, it may still be a good idea to partition the files into subdirectories according to some scheme, just to keep them manageable with various tools (which may have their own issues with humongous directories) such as backup. BTW, opening a directory in Windows explorer counts as such a case.

居里长安 2024-10-12 10:13:03

这取决于您期望拥有多少张图像(如果我们谈论的是千张),则将图片保存在不同的文件夹中可以使计算机更轻松地扫描目录中的文件

it depends how many images you're expecting to have if we're talking about thousand keeping the pictures in diffrent folders make's it easier for the computer to scan the directory for the file

云醉月微眠 2024-10-12 10:13:03

我这样做的方法是使用包含 ID 号的文件夹,

/img/0-100/1
/img/101-200/102

这将为您提供一种查找图像的简单方法,并且文件夹将保持很小。
并且没有扩展名,因为我将其保存在数据库中。

The way i do it is using folder which contain id numbers,

/img/0-100/1
/img/101-200/102

This will give you an easy way of looking up your images and the folder will stay quite small.
And there's no extension because i save this in the database.

你对谁都笑 2024-10-12 10:13:03

是的,一个文件夹中的大量文件可能会减慢对该文件夹中文件的搜索速度。至少在主要操作系统中是这样。理论上不一定是这样。

其他网站也使用该日期。不仅仅是用户 ID 或图像 ID。只是做同样事情的另一种方式。

Yes, lots of files in one folder can slow down seeks for files in that folder. At least in the major OSs. In theory it doesn't have to be that way.

Other sites use the date too. Not just user ids or image ids. Just another way to do the same thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文