在MySQL中的BLOB形象店 [英] Store image in MySQL BLOB

查看:185
本文介绍了在MySQL中的BLOB形象店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL数据库中存储小简图。用PHP我从图像创建缩略图,我只是存储成BLOB列。

I'm storing small thumbs in a MySQL database. With PHP i create a thumbnail from an image and i simply store that into a BLOB column.

似乎MySQL的保存二进制图像作为在数据库中的Base64串。问题是,MySQL的,似乎其存储为应用程序/八位字节流而不是 JPG 文件。

It seems that MySQL saves the binary image as a Base64 string in the database. The problem is that MySQL seems to store it as a application/octet-stream instead of jpg file.

我知道,因为我测试的Base64编码字符串与此code:

I know that because i tested the Base64 string with this code:

<?php
$encoded_string = "....";
$imgdata = base64_decode($encoded_string);

$f = finfo_open();

$mime_type = finfo_buffer($f, $imgdata, FILEINFO_MIME_TYPE);

echo $mime_type;
?>

是MySQL我的自动图像转换成Base64的字符串?如果是这样,是有办法,以确保它并将其作为JPG?

Is MySQL automatically converting my image to a Base64 string? If so, is there a way to make sure it saves it as a JPG?

我知道节约大拇指文件系统比较好,但不幸的是,这是不是这样的,我也不寻找答案将它保存到文件系统。我想知道为什么它被保存为 octed流

I know saving thumbs to the filesystem is better, but unfortunately this is not the case and i am NOT looking for answers to save it to the file system. I want to know WHY it is saved as octed stream.

我用 WideImage 以创建拇指,像这样:

I'm using WideImage to create the thumb, like so:

        $thumb = \WideImage::load ( $filepath )
                            ->resize(117, 88)
                            ->crop ( 'center', 'center', 117, 88 )
                            ->asString('jpg');

变量 $拇指包含有效的二进制数据。因为我可以打印出来,它看起来不错,但也 FWRITE 写了一个良好的JPG。

The variable $thumb contains valid binary data. Because i can print it and it looks good, but also fwrite writes a good JPG.

我然后将它与一个INSERT查询保存到数据库中。但是,当我再重新选择它,它给我回一个 octed流格式。

I then save it to the database with an INSERT query. But when i then SELECT it again it gives me back an octed stream format.

推荐答案

最好的办法是将图像存储在你的文件系统,然后通过MySQL参考它的位置。不推荐使用存储在MySQL中的图像。为什么把一个额外的不需要应变您的数据库?所有大型网站(脸谱等)的文件系统上的存储他们的图像。

The best approach is to store the image on your filesystem and then reference its location via MySQL. Storing images in MySQL is not recommended. Why put an extra unnecessary strain on your database? All of the large websites (Facebook etc) store their images on a filesystem.

这篇关于在MySQL中的BLOB形象店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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