PHP blob存文件,PHP处理blob而不创建文件

您可以拥有一个脚本,可以从数据库中即时打印文件的内容。

您所要做的就是存储其内容类型并从数据库中检索内容。

#showFile.php

$contenttype = ... // retrive content type from database

$blob = ... // retrive blob from database

header('Content-type: ' . $contenttype);

echo $blob;

function mimetype($data)

{

//File signatures with their associated mime type

$Types = array(

"474946383761"=>"image/gif", //GIF87a type gif

"474946383961"=>"image/gif", //GIF89a type gif

"89504E470D0A1A0A"=>"image/png",

"FFD8FFE0"=>"image/jpeg", //JFIF jpeg

"FFD8FFE1"=>"image/jpeg", //EXIF jpeg

"FFD8FFE8"=>"image/jpeg", //SPIFF jpeg

"25504446"=>"application/pdf",

"377ABCAF271C"=>"application/zip", //7-Zip zip file

"504B0304"=>"application/zip", //PK Zip file ( could also match other file types like docx, jar, etc )

);

$Signature = substr($data,0,60); //get first 60 bytes shouldnt need more then that to determine signature

$Signature = array_shift(unpack("H*",$Signature)); //String representation of the hex values

foreach($Types as $MagicNumber => $Mime)

{

if( stripos($Signature,$MagicNumber) === 0 )

return $Mime;

}

//Return octet-stream (binary content type) if no signature is found

return "application/octet-stream";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值