php下将图片以二进制存入mysql数据库中并显示的实现代码
程序员文章站
2023-09-09 17:55:15
//保存图片到数据库的php代码 复制代码 代码如下: if($picture != "none") { $psize = filesize($picture); $mys...
//保存图片到数据库的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;
复制代码 代码如下:
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;
上一篇: 字典生成式