php 输出图片,header('Content-type: image/jpg')问题

tony25800 2011-05-17 03:38:09
小问题,麻烦大家!
本想在sql里边存储图片,先用file_get_contents()读入图片,但不知道为什么用header('Content-type: image/jpg')输出的就是乱码。
代码如下:



<?php

$image = file_get_contents("001.jpg"); //假设当前文件夹已有图片001.jpg
$content=addslashes($image);
header('Content-type: image/jpg');
echo $content;

?>

问什么这样不能echo出来图片呢?
...全文
47288 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
luogailong 2011-08-11
  • 打赏
  • 举报
回复
楼主的代码在ie8下也可显示图形:
$fileres = file_get_contents('d:/a.jpg');
addslashes($filers);
header("Content-type:image/jpg");
echo $fileres;
luogailong 2011-08-11
  • 打赏
  • 举报
回复
下面的代码即ok,在IE8下测试通过
$fileres = file_get_contents('d:/a.jpg');
echo $fileres;
luogailong 2011-08-11
  • 打赏
  • 举报
回复
我也测试通过:
$fileres = file_get_contents('d:/a.jpg');
header('Content-type: image/jpeg');
echo $fileres;
tony25800 2011-05-17
  • 打赏
  • 举报
回复
OK,谢谢你了

[Quote=引用 1 楼 xuzuning 的回复:]
去掉 $content=addslashes($image);
[/Quote]
tony25800 2011-05-17
  • 打赏
  • 举报
回复
是对的

[Quote=引用 6 楼 feng_lqwe 的回复:]

引用 5 楼 kyzy_yy_pm 的回复:
不管怎么着你的addslashes都要去掉

下面是我的测试代码,没问题





$fileres = file_get_contents('d:/a.jpg');
header('Content-type: image/jpeg');
echo $fileres;

测试结果可以?
[/Quote]
tony25800 2011-05-17
  • 打赏
  • 举报
回复
OK了,谢谢你了~

[Quote=引用 5 楼 kyzy_yy_pm 的回复:]

不管怎么着你的addslashes都要去掉

下面是我的测试代码,没问题





$fileres = file_get_contents('d:/a.jpg');
header('Content-type: image/jpeg');
echo $fileres;
[/Quote]
feng_lqwe 2011-05-17
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 kyzy_yy_pm 的回复:]
不管怎么着你的addslashes都要去掉

下面是我的测试代码,没问题





$fileres = file_get_contents('d:/a.jpg');
header('Content-type: image/jpeg');
echo $fileres;
[/Quote]
测试结果可以?
kyzy_yy_pm 2011-05-17
  • 打赏
  • 举报
回复
不管怎么着你的addslashes都要去掉

下面是我的测试代码,没问题





$fileres = file_get_contents('d:/a.jpg');
header('Content-type: image/jpeg');
echo $fileres;
tony25800 2011-05-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 kyzy_yy_pm 的回复:]

没试过,不过你吧$content=addslashes($image);这个去掉了看看
[/Quote]


好像不行啊,这样输出就是乱码
tony25800 2011-05-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xuzuning 的回复:]

去掉 $content=addslashes($image);
[/Quote]

好像不行啊,这样输出就是乱码
kyzy_yy_pm 2011-05-17
  • 打赏
  • 举报
回复
没试过,不过你吧$content=addslashes($image);这个去掉了看看
xuzuning 2011-05-17
  • 打赏
  • 举报
回复
去掉 $content=addslashes($image);

21,887

社区成员

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

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