0

PHPPowerpoint を使用していくつかのグラフを含む pptx ファイルを作成していますが、PHP スクリプトと同じフォルダーに問題なく保存できます。PHPPowerpoint はそれ自体でそれを行います。

作成したpptxファイルをダウンロードしたいのですが、これまでのところ、Webで見つけることができるすべてのオプションを試しました. これは私がそれをやろうとする方法です。

$file = str_replace('generate_report.php', 'export_download.pptx', __FILE__);
header('Content-Description: File Transfer');
header('Content-disposition: attachment; filename="' . $file . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation');
header('Expires: 0');
header('Cache-Control: ');
header('Pragma: ');
flush();
ob_clean();
readfile($file);

スクリプトを実行しても何もダウンロードされません。私の pptx はサーバー上に作成され、問題なく開くことができます。しかし、それはファイルをダウンロードしません。このスレッドからコンテンツ タイプを取得しました: docx、pptx などの正しい MIME タイプは何ですか? . また、他の多くのタイプで試しました。応答をコンソール ログに記録すると、次のような奇妙な文字列 (非常に長い) が表示されます。 +���m���wBhE

これも試しました:

$handle = fopen($file, 'rb');
$buffer = '';
while (!feof($handle)) {
$buffer = fread($handle, 4096);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);

助けてくれる人はいますか?

4

1 に答える 1

2

次のヘッダーは機能するはずです。php://outputまた、ディスク ファイルに保存してからそのディスク ファイルをブラウザにスプールするよりも、直接ストリーミングする方がよい

// Redirect output to a client’s web browser
header('Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation');
header('Content-Disposition: attachment;filename="' . $file . '"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$objWriter->save('php://output');
于 2014-02-05T14:01:36.817 に答える