我正在使用 PHPPowerpoint 创建一个带有一些图表的 pptx 文件,并且将其存储在与 PHP 脚本相同的文件夹中没有问题。PHPPowerpoint 自己做的。
我想在创建 pptx 文件后下载它,到目前为止,我已经尝试了我可以在网络上找到的所有选项。这就是我尝试在ATM上做的方式。:
$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 类型?. 我也尝试了许多其他类型。当我控制台记录我的响应时,我得到一个奇怪的字符串(很长),像这样开始:PKCTDD����[Content_Types].xml͗�n�0E�|E�-J��*�X����� +��������wBhE
也试过这个:
$handle = fopen($file, 'rb');
$buffer = '';
while (!feof($handle)) {
$buffer = fread($handle, 4096);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
有谁能帮忙吗?