将缩略图与mysql数据库中的图像相关联的最佳方法是什么? [英] What is the best way to associate a thumbnail with an image in a mysql database?

查看:126
本文介绍了将缩略图与mysql数据库中的图像相关联的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站数据库,这个网站将成为产品目录。
我的图像表有问题。我有一个PHP脚本,用三种尺寸调整图像大小,用后缀重命名它们,将它们写入目录并在图像表中添加对它们的引用。

I am building a database for a website that will be a cataloge of products. I am having a problem with the table of images. I have a php script that resizes the image with three sizes, renames them with a suffix, writes them to a directory and adds a reference to them in a table of images.

我无法弄清楚缩略图(小图像)将如何与中型和大型图像相关联,因为我计划为每种产品提供多个图像。我希望能够通过php脚本将所有缩略图添加到带有中型或大型图像链接的页面。

I am having trouble figuring out how the thumbnails (the small images) will be associated with the medium and large images since I'm planning to have multiple images for each product. I want to be able to add all thumbnails to a page with a link either to the medium or large image via a php script.

这是我到目前为止所拥有的,

Here is what I have so far,

image-id  product-id  filename              size    caption  width  height  alt
13        1           PassPro150_large.jpg  large   NULL     632    569     NULL
14        1           PassPro150_medium.jpg medium  NULL     250    225     NULL
15        1           PassPro150_small.jpg  small   NULL     115    103     NULL

有没有标准的方法来做到这一点?我应该制作三个表,每个表一个,并将它们与主外键相关联吗?我还以为我可以用字符串操作来做,用_large替换_small,因为上传的所有图像都有相同的后缀。有什么建议吗?

Is there a standard way to do this? Should I make three tables, one for each size and associate them with a primary-foreign key? I also thought I could do it with string manipulation, replace _small with _large since all images uploaded will have the same postfix. Any suggestions?

推荐答案

约瑟夫所说的是一个解决方案。
或者您可以创建多个不同大小的缩略图文件夹,例如thumb_small,thumb_medium,并使用相同名称保存图像。

What Joseph said is one solution. Or you could create multiple folders different sizes of thumbnails, like thumb_small, thumb_medium and save the images in there with same name.

您只需保留文件名数据库。当您需要显示图像时,您将URL调整到特定文件夹。

You just keep the filename in the database. and when you need to display the image you adjust the url to the particular folder.

这篇关于将缩略图与mysql数据库中的图像相关联的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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