ユーザーがphpを使用してpptxおよびzipファイルをダウンロードできるようにするスクリプトに取り組んでいますが、このスクリプトはブラウザーによって動作が異なります。インターネットで入手できる多くのスクリプトを試しましたが、適切に動作しなかったため、さまざまなスクリプトからチャンクを集めて作成しました。
- firefox =>完璧に動作します
- Opera => ファイルを HTM ファイルとしてダウンロード
- Safari => 0kb ファイル
- IE => 古いファイルをキャッチ
私のコード:-
// content type for pptx file
$ctype = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
$file = "http://www.abc.com/presentation.pptx";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: ".$ctype);
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
ob_clean();
flush();
readfile( $file);
上記の一見ランダムな動作を表示する代わりに、すべてのブラウザにファイルを確実にダウンロードさせるにはどうすればよいですか?
編集: 以下は私のために働いたコードです。何が問題なのか、不要なヘッダーまたはファイルパスがわかりませんか? 私は両方の変更を加えましたが、うまくいきました。
$ctype = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
$file = "Presentation3.pptx";
header("Pragma: public");
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: ".$ctype);
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
readfile( $file);