php下将图片以二进制存入mysql数据库中并显示的实现代码

前端之家收集整理的这篇文章主要介绍了php下将图片以二进制存入mysql数据库中并显示的实现代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//保存图片数据库PHP代码
<div class="codetitle"><a style="CURSOR: pointer" data="42866" class="copybut" id="copybut42866" onclick="doCopy('code42866')"> 代码如下:

<div class="codebody" id="code42866">
If($Picture != "none") {
$PSize = filesize($Picture);
$MysqLPicture = addslashes(fread(fopen($Picture,"r"),$PSize));
MysqL_connect($host,$username,$password) or die("Unable to connect to sql server");
@MysqL_select_db($db) or die("Unable to select database");
MysqL_query("INSERT INTO Images (Image) VALUES ($MysqLPicture)") or die("Cant Perform Query");
}else {
echo"You did not upload any picture";
}

//以img标签读取数据库中的图片代码
<div class="codetitle"><a style="CURSOR: pointer" data="34580" class="copybut" id="copybut34580" onclick="doCopy('code34580')"> 代码如下:
<div class="codebody" id="code34580">
MysqL_connect($host,$password) or die("Unable to connect to sql server");
@MysqL_select_db($db) or die("Unable to select database");
$result=MysqL_query("SELECT FROM Images") or die("Cant Perform Query");
While($row=MysqL_fetch_object($result)) {
echo "<IMG SRC="Second.php3? PicNum=$row->PicNum">"; //如secoed.PHP文件代码如下
$result=MysqL_query("SELECT
FROM Images WHERE PicNum=$PicNum") or die("Cant perform Query");
$row=MysqL_fetch_object($result);
Header( "Content-type: image/gif");
echo $row->Image;

猜你在找的PHP相关文章