HTTPのheaderはブラウザを制御してファイルを開けますか?

495 ワード

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);