HTTP的header控制浏览器打开或者下载文件

2019-07-25  本文已影响0人  xuweiqiang

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);
上一篇 下一篇

猜你喜欢

热点阅读