<?php
#写入
$host='127.0.0.1';
$user='root';
$password='root';
$path='filepath';
$file='0x'.bin2hex(file_get_contents($path));
$filewrite=new mysqli($host,$user,$password);
$sql="insert into file (file) values ({$file})";
$filewrite->query($sql);
#读取
function picview($table='file',$where = 1, $filewrite,$colnum = 'file', $type = 'image/png')
{
$sql="select {$colnum} from $table where id={$where}";
$picdata=$filewrite->query($sql);
//展示:
ob_end_clean();
$headerstr = 'Content-type: ' . $type;
Header($headerstr);
// header('Content-type: image/jpeg');
echo $picdata[0][$colnum];
}
?>
blob读写数据库方法,超精简。