您的位置:首页 > 编程语言 > PHP开发

php如何返回一个image文件

2016-03-26 01:21 411 查看
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;

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: