把图片存入数据库中(BASE64)
最近看到某些只使用数据库存储数据却能在应用界面显示图片(SQLite)
于是打开数据库看了下,发现图片都是以 <img src="data:image/gif;base64
, 开头的,gif可以是jpg啥啥啥的
于是去研究了下……….
随便找了一张图片
|
|
图片成功显示,我找的图片是ico格式的…
echo base64的编码结果得到
AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAiWxb/4BhT/+AYU//gGFP/4BhT/+AYU//gGFP/4lsW/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlXpr/7CZjP/p4t7/6eLe/+ni3v/p4t7/6eLe/+ni3v+wmYz/fl9M/wAAAAAAAAAAAAAAAAAAAAAAAAAAfl9M/+ni3v/69/b/////////////////////////////////9/Pw/72roP9+X0z/AAAAAAAAAAAAAAAAgGFP//Xx7v/48+//9ezm//Pn4f/x5Nz/8eHY//Hh1//x4tj/8+Xd//ft5//79/P/ybiu/35fTP8AAAAAiWxb/9vQyf/48e3/hVRF/4VURf+FVEX/hVRF/4VURf+FVEX/hVRF/72ai//m0MP/9ujg//nz7/+wmYz/iWxb/4BhT//48+//9enh/9zDt/+FVEX/hlVG/5drXP+Xalz/l2pb/49gUf+FVEX/lGZX//Hazf/46+P/6NvU/35fTP+AYU//+vTw//Pj2f/dwLH/hVRF/6R6av/u0sL/7tLB/+7Rv//t0L7/qn9v/4VURf/v0sH/9eTZ//Hl3v9+X0z/gGFP//ry7v/z39P/3Lys/4VURf+idmb/6su5/+rKt//qyrb/5cKu/6J1ZP+FVEX/7826//Xg1P/x5Nv/fl9M/4BhT//68uz/8tzP/9u5p/+GVUb/hlVG/4paSv+KWUr/illK/4VURf+FVEX/vZF9/+7Js//03c//8OLZ/35fTP+AYU//+vDq//LYyv/btaH/hVRF/5ZmVv/AlID/wJN//7+Tfv+0iXj/iFhJ/62Hef/68On//fn2/+ni3v9+X0z/gGFP//rv6P/y1sX/2rKc/4VURf+ld2T/7sex//Xg0v/89fH//////5pyZf+FVEX////////////m4N3/fl9M/4BhT//67+j/89bF/9uym/+FVEX/jF1O/6mFev+phnz/qYd8/553a/+FVEX/nHRo////////////zL+4/4lsW/+AYU//++/p//TZyf+FVEX/hVRF/4VURf+FVEX/hVRF/4VURf+bc2f/s5WM//Dq6P//////7+vo/4lsW/8AAAAAgGFP//z28v/57OP//vv5////////////////////////////////////////////9fTy/45wYf8AAAAAAAAAAIBhT//58Or/+fXy//j19P/49fT/+PX0//j19P/49fT/+PX0//j29f/08e//1szH/4JiUP8AAAAAAAAAAAAAAACAYU//gGFP/4BhT/+AYU//gGFP/4BhT/+AYU//gGFP/4BhT/+AYU//gGFP/4lsW/8AAAAAAAAAAAAAAAAAAAAA8A8AAOAHAADAAwAAgAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAABwAAAA8AAA==
然后尝试编码回到文件
|
|
图片文件能打开…..
插入数据库啥的各位自己发挥吧..
参考资料:
Base64:http://baike.baidu.com/view/469071.htm
base64_encode:http://php.net/base64_encode
看了下百度百科各语言对base64的实现,似乎php是最简单的….
PHP是最好的语言(大雾