PHP文件流方式输出文件

1、php输出文件时候,浏览器下载该文件

$file = "./a.png";
header('Content-Disposition:attachment; filename=1.png');
echo file_get_contents($file);

2、PHP输出图片,浏览器中直接打开图片

$file = "./a.png";
header('Content-type:image/png');
echo file_get_contents($file);

3、PHP输出pdf,浏览器直接打开pdf

$file = "wangshili.pdf";
header('Content-Type:application/pdf');
echo file_get_contents($file);

 

posted @ 2019-06-28 17:45  许伟强  阅读(13555)  评论(0编辑  收藏  举报