且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用mysql在php中检索和显示图像

更新时间:2023-01-30 16:32:47

暂时存储临时文件夹,读取拇指文件并存储在数据库中然后取消链接拇指图像
存储在数据库中的图像。

Temporarily stored temp folder,read thumb file and stored in db then unlink thumb image Image stored in DB.

$tname = "./temp/thumb";
$filet = fopen($tname,"rb");
$thumbData = addslashes(fread($filet,filesize($tname)));

insert into image (img_id,img_data) values('','$thumbData');

显示图片

<img src="image.php?img_id=1">

从DB获取图像

$id=$_GET['id'];
   $sql="select img_data from image where img_id=$id";
   $rs=mysql_query($sql) or die (mysql_error());
   $row =mysql_fetch_array($rs,MYSQL_BOTH);
   $data = $row[0];
   print $data;