gpt4 book ai didi

php - 使用 php 显示存储在数据库中的图像(tinyblob)

转载 作者:行者123 更新时间:2023-11-29 04:02:57 25 4
gpt4 key购买 nike

我尝试从数据库 (blob) 中读取图像,但我遇到了问题,因为我不知道图像的 mime 类型。我只有 tinyblob。

我可以读取图像并将其保存回我的硬盘吗?

最佳答案

最好的解决方案是在将图像插入 blob 字段的同时将 mime 类型存储在数据库中。否则,每次检索图像时,您都必须执行以下操作:

$image = $row['imageblob'];  // $row = result row from DB query.

$finfo = new finfo(FILEINFO_MIME);
$mime_type = $finfo->buffer($image);

这在繁忙的系统上很快就会变得非常昂贵,因此最好确定一次,然后存储该结果。

相关PHP docs here .

关于php - 使用 php 显示存储在数据库中的图像(tinyblob),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8042012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com