Home > Backend Development > PHP Tutorial > PHP 图片的二进制存取 (Mysql)

PHP 图片的二进制存取 (Mysql)

WBOY
Release: 2016-06-23 13:59:03
Original
952 people have browsed it

保存图片的字段 数据类型为:blob

 

img.php


<?php $filename = "Admin/Upload/3025994.jpg";// 读取文件$fp = fopen($filename,"rb");$data   =   addslashes(fread($fp,filesize($filename)));fclose($fp);// 操作MYSQL$conn=mysql_connect("localhost","root","admin");@mysql_select_db("mytest",$conn);// 存入数据库$query="insert into pic values (5,'$data')";$result=mysql_query($query);$id=mysql_insert_id(); //读取数据$query="select * from pic where picid=5 limit 0,1";$result=mysql_query($query);$row=mysql_fetch_array($result);$data = $row["Pic"];// 显示文件header("Content-type: image/*");echo $data;?>
Copy after login

在其他页面如下形式引用:

 

PHP 图片的二进制存取 (Mysql)


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template