在文件夹中存储数百万张图像的更好解决方案?

发布于 2024-11-10 02:37:43 字数 544 浏览 4 评论 0原文

我计划根据图片的类型和大小将图片存储在文件夹中:

images/{OBJECT}/{OBJECT_ID}/{OBJECT_ID} _{SIZE}.jpg

// FOLDERS LOOK LIKE THIS:
images/product/14/14_thumb.jpg
images/product/14/14_large.jpg
images/category/124/124_large.jpg
...

根据这种方法,我可以轻松地用很小的力气到达任何物体:

function get_image($OBJECT, $OBJECT_ID, $SIZE){
    ...
}
// get image
get_image('product', 14, 'large');

我认为这对我来说已经足够好了,但我想确定......也许我是缺少一些东西。

那么你觉得怎么样?

I am planing to store my pictures in folders according to their types and sizes:

images/{OBJECT}/{OBJECT_ID}/{OBJECT_ID}_{SIZE}.jpg

// FOLDERS LOOK LIKE THIS:
images/product/14/14_thumb.jpg
images/product/14/14_large.jpg
images/category/124/124_large.jpg
...

According to this approach, I can easily reach any object with a small effort:

function get_image($OBJECT, $OBJECT_ID, $SIZE){
    ...
}
// get image
get_image('product', 14, 'large');

I think it is good enough for me, but I want to be sure... Maybe I am missing something.

So what do you think?

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

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

发布评论

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

评论(3

浪推晚风 2024-11-17 02:37:43

这还不够好。
将 ID 分解为一些部分,每个部分将是目录级别的名称。
例如,ID 445578 您可以存储在
/44/55/78/445578.jpg

/4/4/5/445578.jpg
尺寸可以是后缀,是的。

你需要这样做,因为你可以拥有超过 32k 的 ID,但文件夹并不总是可以保存超过 32k 的文件。

It's not good enough.
Explode ID to some count of parts, and each part will be the name of the directory level.
For example, ID 445578 you can store in
/44/55/78/445578.jpg
or
/4/4/5/445578.jpg
Size can be a suffix, yes.

You need to do it, because you can have more than 32k of IDs, but folder not always can keep more than 32k of files.

蹲墙角沉默 2024-11-17 02:37:43

这绝对没有什么问题!

There is absolutely nothing wrong with this!

翻身的咸鱼 2024-11-17 02:37:43

根据实际情况,这有几个问题。

如果这些图像免费向公众开放,那么唯一的争论就是当人们形成其他网站直接链接到您网站上的图像时所使用的带宽。

如果这些图像不是免费且不公开的,就会出现大问题。无论您选择什么网址命名,如果在分析几个网址后可以预测它,那么就可以直接访问其余的图像。

您应该查看您正在使用的脚本语言中的 url 重写。在您的编程中,您应该检查引用者、身份验证、授权和配额。

关键是图像的物理位置与 url 引用的位置不同。

there are several things wrong with this depending on what is really going on.

if these images free for public, then the only argument would be bandwidth that would get used when people form other sites link to images directly on your site.

if these images are not free and not public, there are big problems. Whatever url naming you choose if it can be predicted after analysing a few urls, then the rest of the images can be directly accessed.

you should look at url rewriting in the scripting language that you are using. and in your programming you should check for referer, authentication, authorization and quota.

The point being that the physical location of the images would be different from the location referred to by the url.

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