Home  >  Article  >  Backend Development  >  求教:使用PHP的函数fpassthru()显示图片详解,该怎么处理

求教:使用PHP的函数fpassthru()显示图片详解,该怎么处理

WBOY
WBOYOriginal
2016-06-13 13:36:191053browse

求教:使用PHP的函数fpassthru()显示图片详解
新学PHP,可能没问到点子上,大概意思是这样的:

wamp环境,zend框架+smarty模板

1. 求教:使用PHP的函数fpassthru()显示图片详解,该怎么处理 然后在action里边用fpassthru传递一个图片来显示 是否可行? 怎么写?

2. 不用img标签 用fpassthru 可以传递图片到前台么?

------解决方案--------------------
...Action{
//1可以直接输出图片内容例如用你说的fpassthru:

PHP code

// 以二进制格式打开文件
$name = './img/ok.png'
$fp = fopen($name, 'rb');

// 发送合适的报头
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));

// 发送图片并终止脚本
fpassthru($fp);
exit;

------解决方案--------------------
apache 下防盗链可以用rewrite_module,用这些输出文件头的方法来处理只会让服务器负担加重.

http://sealbird.iteye.com/blog/976891
------解决方案--------------------
探讨

楼上发的昨天我也搜到过,不过试了下,没成功 不知道是哪里的问题

后边的'rb' 应该是参数吧 这个参数我查了手册没查到 所以想来提问一下看看有没有更有用的资料

------解决方案--------------------
注释掉 header("Content-Length: " . filesize($imgpath));

header("Content-Type: image/jpg");
后,只能是图片数据流
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn