douguwo2275
2011-11-07 20:12
浏览 151
已采纳

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

I try to read image from database (blob) but i have problem becouse i don't know mime type of image. I have only tinyblob.

Can i read image and save it back to my hard disk?

图片转代码服务由CSDN问答提供 功能建议

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

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • dongye3917 2011-11-07 20:18
    最佳回答

    The best solution is to store the mime-type in the DB at the same time you're inserting the image into the blob field. Otherwise you're going to have to the following EACH TIME the image is retrieved:

    $image = $row['imageblob'];  // $row = result row from DB query.
    
    $finfo = new finfo(FILEINFO_MIME);
    $mime_type = $finfo->buffer($image);
    

    This gets to be expensive very quickly on a busy system, so best do the determination ONCE and then store that result.

    Relevant PHP docs here.

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题