将图像文件添加到数据库表中

发布于 2024-10-10 09:28:55 字数 52 浏览 0 评论 0原文

如何将图像文件添加到 mysql 表。我是一名程序员,我正在使用 php 和 mysql。

how to add image file/s to mysql table.I am a programmer I am using php and mysql.

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

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

发布评论

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

评论(3

喜爱纠缠 2024-10-17 09:28:55

您不应该为网站添加图像本身。您将图像上传到服务器,然后将路径保存到数据库中。然后您应该能够将文件的路径输出为 HTML。

You shouldn't add the image itself for websites. You upload the image to the server and then save the path into the database. You should be able to then output the path of the file to HTML.

握住我的手 2024-10-17 09:28:55

您需要使用blob(或mediumbloblongblob,具体取决于您要支持的图像的最大大小)数据类型来存储二进制数据。

插入之前,请务必对二进制图像数据中的特殊字符进行转义。

 $img_data =mysql_real_escape_string(file_get_contents($filename));

You need to use blob (or mediumblob or longblob depending on the maximum size of images you want to support) data type for storing binary data.

Before inserting, be sure to escape special characters in the binary image data.

 $img_data =mysql_real_escape_string(file_get_contents($filename));
最偏执的依靠 2024-10-17 09:28:55

我通常存储图像文件的 url 而不是文件本身(不太确定你会如何做到这一点)。我建议存储 url 并使用

I usually store the url of the image file rather than the file itself (not too sure how you would do that anyway). I recommend storing the url and using

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