图像上传——BLOB 是正确的选择吗?

发布于 2024-12-03 02:22:23 字数 1470 浏览 8 评论 0原文

可能的重复:
在数据库中存储图像 - 是或否?
要做或不做:将图像存储在数据库

我目前正在创建我朋友的艺术家作品集网站。她要求我创建一个简单的系统,她可以在其中上传图像,并且图像将根据图像所属的类别显示在网站上。我偶然发现了几种有用且有趣的方法来实现这一目标,并且我已将其范围缩小到对我来说最有用的两种。不幸的是,我不知道哪一个是更好的选择。

选项Ahttp://www.phpriot.com/文章/images-in-mysql

此方法使用一种非常有争议的方式在 mySQL 中存储图像 使用 blob 数据类型的表。我读到不推荐这样做 然而,对于许多 PHP 程序员来说,它似乎确实适合我的 需要完美。据我了解,这相当简单和容易:

  1. 将图像上传到数据库
  2. 根据所选类别显示数据库中的图像。

选项 B: http://webdeveloper.com/forum/ showthread.php?t=101466

此方法仅显示如何使用以下命令将图像上传到目录 PHP。我想一旦完成,我就可以列出所有 该目录中的图像并将其放入数组中。之后循环 遍历数组并在 标记中显示这些项目。

所以,你看,我仍在学习如何使用 PHP 和 mySQL,这个网站是学习的巨大动力。但是,我不确定 使用哪种方法,或者大多数 Web 开发人员是否使用单一方法?

需要思考的问题 // TL;DR

  • 你们大多数人使用的上传图像的最佳方法是什么?
  • 您会考虑使用 mySQL 'blob' 数据类型吗?
  • 如果将图像上传到文件目录是最好的,我将如何显示 图像 - 使用数组、将图像列表放入数据库或完全不同的东西(因为我是菜鸟,不知道更好)

提前感谢您的回复!

Possible Duplicate:
Storing Images in DB - Yea or Nay?
To Do or Not to Do: Store Images in a Database

I'm currently in the process of creating my friend's artist portfolio website. She asked me to create a simple system where she can upload an image and it will be displayed on the site according to the category it is in. I've stumbled upon several useful and interesting ways in which to achieve this and I've narrowed it down to the two that seem the most useful for me. Unfortunately, I do not know which one would be a better choice.

Option A: http://www.phpriot.com/articles/images-in-mysql

This method uses a very controversial way of storing images in a mySQL
table using the blob datatype. I've read that it isn't recommended
by many PHP programmers, however, it does seem like it can fit my
needs perfectly. From what I understand it is fairly simple and easy:

  1. Upload Image to DB
  2. Display Image from DB according to category chosen.

Option B: http://webdeveloper.com/forum/showthread.php?t=101466

This method only shows how to upload an image to a directory using
PHP. I figured once that is done I could make a simple list of all the
images in that directory and put it into an array. Afterwards loop
through the array and display those items in <img> tags.

So, you see, I am still learning how to work with PHP and mySQL and this website is great motivation to learn. However, I'm unsure
of which method to use, or if there is a single method most web developers use?

Questions to Think About // TL;DR

  • What is the best method for uploading images that most of you use?
  • Would you consider using mySQL 'blob' datatype?
  • If uploading the image to a file directory is best, how would I display
    the images--using an array, placing the list of images in a DB, or something entirely different (because I'm a noob and don't know any better)

Thanks in advance for any replies!

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

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

发布评论

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

评论(2

空名 2024-12-10 02:22:23

我不会使用数据库存储来存储大图像,只需上传它们并将文件路径/名称和详细信息写入数据库即可。如果您需要按特定顺序检索图像,请在数据库中设置优先级字段

今天刚刚发现 Uploadify,可以使用伟大的

I wouldn't use database storage for large images, just upload them and write the file path/name and details into a database. Have a field in the database for Priority if you need to retrieve the images in a specific order

Just found Uploadify today, works great

寻找一个思念的角度 2024-12-10 02:22:23

我在我正在处理的一个项目中使用它,而无需将文件写入磁盘的方法是使用文本列,将图像作为 base64 字符串编码数据。这样做的好处是,您可以通过 Data uri 将文件直接输出到浏览器(此处的信息:http:// en.wikipedia.org/wiki/Data_URI_scheme)。

I use this on a project i'm working on and the way to go without having to write the files to disk is using a text column with the image as base64 string encoded data. The beauty of this is that you can output the file directly to browser via Data uri (info here: http://en.wikipedia.org/wiki/Data_URI_scheme).

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