
2007年12月25日
PDFファイルダウンロードDE表示
/**
* ファイルダウンロード処理
* ダウンロードの際は「Content-Disposition: inline」により、
* ダウンロードダイアログが表示されず、ブラウザのプラグインで
* 開きます。
* @param filename PDFファイルのフルパス名
* @return 0:成功 -1:失敗
*/
public static function downloadPdf($filename) {
if( !file_exists($filename) ) {
return -1;
}
$filesize = filesize($filename);
header("Content-Disposition: inline; filename=".basename($filename));
header("Content-Length: " . $filesize);
header("Content-Type: application/pdf");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: private");
$handle = fopen($filename, "rb");
while (!feof($handle)) {
echo fread($handle, 4096);
flush();
}
fclose($handle);
return 0;
}
良かったらクリックお願いします→

HTTPヘッダについて(Expires)
PDFファイルダウンロードDE表示とファイルダウンロード処理でのHTTPヘッダについて、いくつかメモ。
"Expires: 0"については、以下を参照としています。
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
>HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past (i.e., "already expired").
Expiresには、日付だけでなく「期限切れ」を表す"0"を設定することもできるとのことですね。
ただ、safariは"Expires: 0"の記述に対応していないという、不穏な噂があるような、ないような
良かったらクリックお願いします→
"Expires: 0"については、以下を参照としています。
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
>HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past (i.e., "already expired").
Expiresには、日付だけでなく「期限切れ」を表す"0"を設定することもできるとのことですね。
ただ、safariは"Expires: 0"の記述に対応していないという、不穏な噂があるような、ないような

良かったらクリックお願いします→
