2017-10-08 54 views
0

如何修改以下脚本(Summary.php),以便所提供的PPTX文件名不是“Summary.php”,并且我的服务文件未命名为Summary.php.pptx?PHPPresentation - 如何自定义服务(可在浏览器中下载)文件的文件名不是调用PHP脚本的文件名?

我使用的技术是将PowerPoint文件的内容放入浏览器,但我故意要将文件名更改为至少不包含.php,但充其量只能是像指定的Presentation.pptx这样的自定义名称在我的php头下面。

Summary.php

require_once 'vendor/phpoffice/phppresentation/vendor/autoload.php'; 
use PhpOffice\PhpPresentation\PhpPresentation; 
use PhpOffice\PhpPresentation\IOFactory; 
use PhpOffice\PhpPresentation\Style\Alignment; 
use PhpOffice\PhpPresentation\Style\Color; 
use PhpOffice\PhpPresentation\Style\Fill; 
use PhpOffice\PhpPresentation\Style\Border; 


class Presentation 
{ 
    function generatePresentation() 
    { 
     header("Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation; filename=Presentation.pptx"); 
     $oWriterPPTX = IOFactory::createWriter($this->objPhpPresentation,'PowerPoint2007'); 
     $oWriterPPTX->save('php://output'); 
    } 
} 

编辑

解决方案

header("Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation"); 
    header("Content-Disposition: attachment; filename=Presentation.pptx"); 
    $oWriterPPTX = IOFactory::createWriter($this->objPhpPresentation,'PowerPoint2007'); 
    $oWriterPPTX->save('php://output'); 

回答

相关问题