ログインとかしてないと pdf をダウンロードできないようにしようと思って、pdf を非公開領域に置いて、いかのようなコードを書いたんですよ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mime_type = 'application/pdf'; | |
$file_path = '/path/to/pdf'; | |
header('Content-Disposition: inline; filename="'.basename($file_path).'"'); | |
header('Content-Length: '.filesize($file_path)); | |
header('Content-Type: '.$mime_type); | |
readfile($file_path); |
そしたら https な環境で IE 8 からダウンロードできないってクレームががが…
IE5 – IE8 では https 環境で Cache-control:no-cache へっだが付いてるとダウンロードできないんですって…
Internet Explorer file downloads over SSL do not work with the cache control headers
そこで以下のようになおしました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mime_type = 'application/pdf'; | |
$file_path = '/path/to/pdf'; | |
// for IE 8 ( see http://support.microsoft.com/kb/323308/ja ) | |
$expires = 30; | |
header("Last-Modified: ". gmdate("D, d M Y H:i:s", filemtime($file_path)). " GMT"); | |
header("Expires: " . date(DATE_RFC1123, time() + $expires)); | |
header("Pragma: cache"); | |
header("Cache-Control: max-age={$expires}"); | |
header("Cache-Control: cache"); | |
// for IE 8 | |
header('Content-Disposition: inline; filename="'.basename($file_path).'"'); | |
header('Content-Length: '.filesize($file_path)); | |
header('Content-Type: '.$mime_type); | |
readfile($file_path); |
IE8めー
コメントを残す