首页 > Web开发 > 详细

php如何返回一个image文件

时间:2016-03-26 06:38:13      阅读:297      评论:0      收藏:0      [点我收藏+]

The important points is that you must send a Content-Type header. Also, you must be careful not include any extra white space (like newlines) in your file before or after the <?php ... ?> tags.

As suggested in the comments, you can avoid the danger of extra white space at the end of your script by omitting the ?> tag!

<?php

  $img = ‘./test.png‘;

  $fp =fopen($img, ‘rb‘);

  //send the right headers

  header("Content-Type: image/png");

  header("Content-Length: ".filesize($img));

  //dump the picture and stop the script

  fpassthru($fp);

  exit;

?>

 

php如何返回一个image文件

原文:http://www.cnblogs.com/dxwhut/p/5321808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!