按道理来说,图片是应该按照路径存在数据表中的,由于工作需要,需要将图片以二进制流的情况存入数据库,现在将数据表table中一个字段picture,类型改为 longblob,已经能成功将二进制流写入该字段,可是我需要将该图片在内容页中显示出来,以下代码是我在图片的位置嵌入的php代码,图片死活不显示,大家帮忙看看怎么回事?(存入数据库的图片也是jpg格式的)
<?php
include("config.php");
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$sql=mysql_query("SELECT * FROM table where id=5") or die("Can't Perform Query");
Header( "Content-type: image/jpg");
$r=mysql_fetch_object($sql);
echo $r->picture;
?>
其中config.php包含了变量的定义
<?php
include("config.php");
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$sql=mysql_query("SELECT * FROM table where id=5") or die("Can't Perform Query");
Header( "Content-type: image/jpg");
$r=mysql_fetch_object($sql);
echo $r->picture;
?>
其中config.php包含了变量的定义
include("config.php");
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$sql=mysql_query("SELECT * FROM table where id=5") or die("Can't Perform Query");
Header( "Content-type: image/jpg");
$r=mysql_fetch_object($sql);
echo imagecreatefromstring($r->picture);
?>
imagecreatefromstring();
mysql_connect("localhost","root","123456");
mysql_select_db("test");$query=mysql_query("select * from image");
while($row=mysql_fetch_object($query)){
Header( "Content-type: image/gif");
echo $row->picture1;
echo $row->picture2;
echo $row->picture3;
}
?>新手求知!!!
这位兄弟,看看这篇文章,就能解决每次只显示一张照片的问题
多谢各位朋友的帮助,正是大家集思广益,我才受到启发,同时也学会了不少新知识,比如imagecreatefromstring等等
这位兄弟,看看这篇文章,就能解决每次只显示一张照片的问题
多谢各位朋友的帮助,正是大家集思广益,我才受到启发,同时也学会了不少新知识,比如imagecreatefromstring等等