微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐