显示数据库中blob类型的图片,我图片显示不出来

初夏_90 2013-05-17 09:03:52
showimage.php
<?php  
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/utilityfunction/SqlHelp.class.php';
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/Comm.class.php';

$SqlHelper = new SqlHelp ( 'read', 'qztoa' );
$sql = "select * from qzt_image";
$query = $SqlHelper->query($sql );
$query_num = $SqlHelper->num_rows ($query );

$rows = array ();
$retarr = array ();
$query =$SqlHelper->query ( $sql );
if($query)
{
$arr_teainfo2 = array ();
while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {
$arr_teainfo2 [] = $arr_teainfo;
$Id=$arr_teainfo["Id"];
echo $arr_teainfo["Id"];
echo "<IMG SRC=\"Second.php3?Id=$Id\">";

}
}



?>


Second.php3
<?php  
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/utilityfunction/SqlHelp.class.php';
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/Comm.class.php';

$SqlHelper = new SqlHelp ( 'read', 'qztoa' );
$sql = "select * from qzt_image where Id=10";
$query = $SqlHelper->query($sql );
$query_num = $SqlHelper->num_rows ($query );

$rows = array ();
$retarr = array ();
$query =$SqlHelper->query ( $sql );
if($query)
{
$arr_teainfo2 = array ();
while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {
$arr_teainfo2 [] = $arr_teainfo;
$Id=$arr_teainfo["Id"];
$imagetype=$arr_teainfo["imagetype"];
//echo $arr_teainfo["images"];
//Header( "Content-type: $imagetype");
header('Content-type: $imagetype');
echo $arr_teainfo["images"];

}
}

?>


请问我哪里有问题?PHP新人,不知道哪里错了
...全文
1415 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
初夏_90 2013-05-21
  • 打赏
  • 举报
回复
引用 18 楼 qvbfndcwy 的回复:
<?php
$query = "select * from qzt_image where id=10";
$result = mysql_query($query);
$row = @mysql_fetch_array($result);
Header( "Content-type: image/pjpeg");
echo "$row[uploadfile]";
?>
我的原始版代码。 是pjpeg哦。
我用pjpeg还是显示不出来,我用的gbk的格式,请问你用的什么格式?
初夏_90 2013-05-21
  • 打赏
  • 举报
回复
引用 17 楼 xuzuning 的回复:
你的图片格式有问题!

这样吧,你把 $image 写到文件里,比如 file_put_contents('test.jpg', $image);
然后把他发上来

可以正常写入的

原来 test.jpg是另一张图,写入后就是这张图了
初夏_90 2013-05-21
  • 打赏
  • 举报
回复
引用 17 楼 xuzuning 的回复:
你的图片格式有问题! 这样吧,你把 $image 写到文件里,比如 file_put_contents('test.jpg', $image); 然后把他发上来
前几天放假了,昨天请假了,等下我传上去
qvbfndcwy 2013-05-18
  • 打赏
  • 举报
回复
<?php
$query = "select * from qzt_image where id=10";
$result = mysql_query($query);
$row = @mysql_fetch_array($result);
Header( "Content-type: image/pjpeg");
echo "$row[uploadfile]";
?>
我的原始版代码。 是pjpeg哦。
xuzuning 2013-05-17
  • 打赏
  • 举报
回复
浏览器地址栏 http://localhost/Second.php3?Id=10 能开到什么?
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
引用 8 楼 blizzf99 的回复:
[quote=引用 6 楼 yy1106300249 的回复:] [quote=引用 5 楼 blizzf99 的回复:] 图片显示不出来,是程序报错?还是路径不对。 先打印下,看有数据没,如果有,再看下,显示的路径是否正确。
先运行php3把image打印出来了,正常的,没有报错

<?php  
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/utilityfunction/SqlHelp.class.php';
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/Comm.class.php';

$SqlHelper = new SqlHelp ( 'read', 'qztoa' );
$sql = "select * from qzt_image where Id=10";
$query = $SqlHelper->query($sql );
$query_num = $SqlHelper->num_rows ($query );

$rows = array ();  
$retarr = array (); 
$query =$SqlHelper->query ( $sql );
if($query)
{
$arr_teainfo2 = array ();
while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {
$arr_teainfo2 [] = $arr_teainfo;
$Id=$arr_teainfo["Id"];
$imagetype=$arr_teainfo["imagetype"];
$image= $arr_teainfo["images"];
}
//header('Content-type: image/jpeg ');
echo $image; 


}


[/quote] 程序没报错,把输出的数据复制到地址栏,有图片显示没??[/quote] 这个存的不是图片的地址,而是blob数据类型的
blizzf99 2013-05-17
  • 打赏
  • 举报
回复
引用 6 楼 yy1106300249 的回复:
[quote=引用 5 楼 blizzf99 的回复:] 图片显示不出来,是程序报错?还是路径不对。 先打印下,看有数据没,如果有,再看下,显示的路径是否正确。
先运行php3把image打印出来了,正常的,没有报错

<?php  
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/utilityfunction/SqlHelp.class.php';
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/Comm.class.php';

$SqlHelper = new SqlHelp ( 'read', 'qztoa' );
$sql = "select * from qzt_image where Id=10";
$query = $SqlHelper->query($sql );
$query_num = $SqlHelper->num_rows ($query );

$rows = array ();  
$retarr = array (); 
$query =$SqlHelper->query ( $sql );
if($query)
{
$arr_teainfo2 = array ();
while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {
$arr_teainfo2 [] = $arr_teainfo;
$Id=$arr_teainfo["Id"];
$imagetype=$arr_teainfo["imagetype"];
$image= $arr_teainfo["images"];
}
//header('Content-type: image/jpeg ');
echo $image; 


}


[/quote] 程序没报错,把输出的数据复制到地址栏,有图片显示没??
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
上面代码贴出来多了<BR><BR> ,我程序里没有的
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
引用 5 楼 blizzf99 的回复:
图片显示不出来,是程序报错?还是路径不对。 先打印下,看有数据没,如果有,再看下,显示的路径是否正确。
先运行php3把image打印出来了,正常的,没有报错

<?php  
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/utilityfunction/SqlHelp.class.php';
include_once dirname(dirname (dirname ( __FILE__ ))). '/yeqztsys1.0/Comm.class.php';

$SqlHelper = new SqlHelp ( 'read', 'qztoa' );
$sql = "select * from qzt_image where Id=10";
$query = $SqlHelper->query($sql );
$query_num = $SqlHelper->num_rows ($query );

$rows = array ();  
$retarr = array (); 
$query =$SqlHelper->query ( $sql );
if($query)
{
$arr_teainfo2 = array ();
while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {
$arr_teainfo2 [] = $arr_teainfo;
$Id=$arr_teainfo["Id"];
$imagetype=$arr_teainfo["imagetype"];
$image= $arr_teainfo["images"];
}
//header('Content-type: image/jpeg ');
echo $image; 


}


blizzf99 2013-05-17
  • 打赏
  • 举报
回复
图片显示不出来,是程序报错?还是路径不对。 先打印下,看有数据没,如果有,再看下,显示的路径是否正确。
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
我测试了,.php3可以正常解析的,但是还是不行啊谁帮下啊
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
1、你的 php3 类型文件能被正确解析吗?检查一下配置文件 2、如果程序文件时 utf-8 编码的,请确认都没有 BOM 头 3、Second.php3 输出图片不要用循环
我程序文件是gbk的
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
1、你的 php3 类型文件能被正确解析吗?检查一下配置文件 2、如果程序文件时 utf-8 编码的,请确认都没有 BOM 头 3、Second.php3 输出图片不要用循环
我在httpd.conf文件里面加了AddType application/x-httpd-php .php .html .htm .php3 这样是不是就能正常解析php3 类型文件了?
xuzuning 2013-05-17
  • 打赏
  • 举报
回复
1、你的 php3 类型文件能被正确解析吗?检查一下配置文件 2、如果程序文件时 utf-8 编码的,请确认都没有 BOM 头 3、Second.php3 输出图片不要用循环
xuzuning 2013-05-17
  • 打赏
  • 举报
回复
你的图片格式有问题! 这样吧,你把 $image 写到文件里,比如 file_put_contents('test.jpg', $image); 然后把他发上来
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
引用 13 楼 xuzuning 的回复:
一大堆乱七八糟的?没关系,截个图
能看懂吗,那些乱七八糟的,不知道什么东西
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
下面还有好多好多
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
截个图都卡半天
xuzuning 2013-05-17
  • 打赏
  • 举报
回复
一大堆乱七八糟的?没关系,截个图
初夏_90 2013-05-17
  • 打赏
  • 举报
回复
引用 10 楼 xuzuning 的回复:
浏览器地址栏 http://localhost/Second.php3?Id=10 能开到什么?
我测试的id为10的图片是jpg的,所以我先写出固定的header('Content-type: image/jpeg ');
加载更多回复(1)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧