如何在MySql中插入图像和文本?
我正在尝试准备一个示例试卷准备应用程序。 我正在使用 tinyMCE 编辑器和 ajax-file-uploader 插件 - 因为有些问题可能需要图像和文本。 如何使用 PhP 将包含图像和文本的问题存储到 MySql 中?
I am trying to prepare a sample question paper preparation app.
I am using tinyMCE editor and ajax-file-uploader plugin with it - as some questions may need images along with text.
How do I store my questions that have both image and text into MySql using PhP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议将图像存储在某种 NAS 或其他位置,并将图像的路径以及相应字段中的其他数据存储在数据库中。
您可以将图像存储在数据库中,但从数据库检索图像并将其呈现给用户并不是一个好主意(它的性能也不是很好)。可能会影响性能
I would suggest storing the image on some sort of NAS or some other location, and store the path to the image in the database along with the other data in respective fields.
You can store the image in the DB but it is not good idea to retrieve and present the image from the database to the user (It doesn't perform that great either). There might be a performance hit
MySQL 处理图像的能力非常好。将它们插入到 BLOB 中。另一方面,您可以将图像文件名和路径或链接作为文本存储在数据库中。
哪种解决方案最好取决于您的应用程序的要求。一般来说,如果你有大量的图像,你的数据库就会变得很大,备份也会很慢。为了存储大量图像,可能会对您的文件系统产生类似的影响。
这是有趣的 Microsoft To BLOB or not to BLOB 论文,这将为您提供有关该主题的更多信息,甚至一些指标。
MySQL handles images very well. You insert them in BLOBs. On the other hand you could store the image file name and path or a link, as text in your DB.
Which solution is the best depends on the requirements of your application. In general if you have a huge amount of images, your database will become huge and backing up will be slow. There might be a similar impact on your file system in order to store a huge amount of images.
Here is the interesting Microsoft To BLOB or not to BLOB paper, that will give you more information on the topic and even some metrics.
我会回应@harigm和@Costis Aivalis已经给出的答案,但如果你真的想“全力以赴”并将HTML内容和图像存储在同一个BLOB中,为什么不看看RFC 2557,它允许你使用 url 方案
data:
将二进制数据(如图像)放置在文档本身中。为了完成这项工作,您需要在 HTML 返回到您的服务器后对其进行解析,并对要放置在 HTML 中的所有图像进行 Base64 编码,这是一项相当大量的工作,但结果可能不会有什么回报。I would echo the answers already given by @harigm and @Costis Aivalis but if you really wanted to go "all out" and store both the HTML content and the images in the same BLOB why not have a look at RFC 2557 which allows you to place binary data (like images) in the document itself using the url scheme
data:
. To make this work you will need to parse your HTML once it gets back to your server and base64 encode all the images to be placed in the HTML, quite a lot of work for what would probably turn out to be little reward.