php图片存在数据库中 php把图片保存到数据库

怎样把图片插入到数据库中 php保存图片到数据库做什么?保存到本地使用起来也方便 , 真要保存通过base64字符串保存 。
?php
header('Content-type:text/html;charset=utf-8');
//读取图片文件 , 转换成base64编码格式
$image_file = './image123.jpg';
$image_info = getimagesize($image_file);
$base64_image_content = "data:{$image_info['mime']};base64," . chunk_split(base64_encode(file_get_contents($image_file)));
// $base64_image_content 输入到数据库
//保存base64字符串为图片
//匹配出图片的格式
if (preg_match('/^(data:\s*image\/(\w );base64,)/', $base64_image_content, $result)){
$type = $result[2];
$new_file = "./test.{$type}";
if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))){
echo '新文件保存成功:', $new_file;
}
}
?
img src="http://img.readke.com/240910/02592aZ8-0.jpg echo $base64_image_content;?" /
php 文章图片怎样存入数据库??一般来说,图片不会存入数据库的,图片都是上传到服务器里的一个路径下 , 数据库的字段栏位只记录这张对应图片的路径,图片显示是在读取数据库的内容,并显示字段记录对应的URL 。
php图片保存到数据库1.图片转换 将上传php图片存在数据库中的图片读取到一个字符串中,再用base64对数据进行编码 $img =base64_encode(file_get_contents($_FILES['file_head']['tmp...
2.显示图片 imgsrc="https://www.04ip.com/post/{$base64String}" 这样就能把图片显示出来php图片存在数据库中了
【php图片存在数据库中 php把图片保存到数据库】php图片存在数据库中的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于php把图片保存到数据库、php图片存在数据库中的信息别忘了在本站进行查找喔 。

    推荐阅读