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

yipeiwu_com5年前Mysql基础
//保存图片到数据库的php代码
复制代码 代码如下:

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标签读取数据库中的图片的代码
复制代码 代码如下:

mysql_connect($host,$username,$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;

相关文章

解析link_mysql的php版

复制代码 代码如下:<?php$str_sql_read="select count(*) as num from userinfo";$str_sql_del="delete f...

PHP Warning: PHP Startup: Unable to load dynamic library \ D:/php5/ext/php_mysqli.dll\

PHP Warning: PHP Startup: Unable to load dynamic library \ D:/php5/ext/php_mysqli.dll\

今天在家启动PHP环境的时候,突然发现不能加载php_mysqli.dll了,网上找了一圈,没有解决方案! 在群里面受一哥们儿的启发,竟然解决了,如果你的问题还没有解决,请按下面的方法试...

PHP中addslashes与mysql_escape_string的区别分析

本文实例分析了PHP中addslashes与mysql_escape_string的区别。分享给大家供大家参考,具体如下: 1.在插入数据时两者的意义基本一样.区别只在于addslash...

php连接mysql数据库最简单的实现方法

在连接MySQL数据库之前,您必须指定以下信息: MySQL数据源名称或DSN:指定MySQL数据库服务器的地址。您可以使用IP地址或服务器名称,例如,127.0.0.1 或 local...

MySQL授权问题总结

我用localhost的root帐号不能连 最后请教DBA组新建用户搞定! 现弄些受权用户的资料 以备不时之需 授权表使用举例 grant用于给增加用户和创建权限,r...