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
As suggested in the comments, you can avoid the danger of extra white space at the end of your script by omitting the
<?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 ... ?>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代码删除指定目录下的所有文件
- 利用php实现获取一个文件中一个单词或者字符串出现的次数
- php base64数据与图片的转换
- 【解决】WordPress FTP连接服务器时出错,请检查设置,WordPress需要访问您网页服务器的权限
- laravel5 的中间件的使用 (1)
- php编程中echo用逗号和用点号连接的区别
- 在windows(64)下安装php开发环境wamp+yaf框架+phpstorm以及Tortois
- PHP 数据类型
- Laravel Eloquent Orm 使用指南
- laravel控制器使用中间件
- getAttribute()与getParameter()
- php ci 获取表单中多个同名input元素值的代码
- 学习PHP编程的方法。
- wget完成ftp链接下载
- php使用curl来获取远程图片
- PHP创建文件,并向文件中写入数据,覆盖,追加的实现代码
- php用正则判断是否为数字的方法
- PHP判断FORM表单或URL参数来的数据是否为整数的方法
- PHP文件操作之文件的类型和属性
- php如何控制用户对图片的访问 PHP禁止图片盗链