2017-10-08 4 views
0

提供されたPPTXファイル名が "Summary.php"でなく、サービス対象ファイルの名前がSummary.php.pptxにならないように、次のスクリプト(Summary.php)を変更するにはどうすればよいですか?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'); 
    } 
} 

EDIT

ソリューション

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'); 

答えて

1

あなたはContent-Dispositionレスポンスヘッダを使用する必要があります。例えば。

Content-Disposition: attachment; filename="filename.jpg" 

参考:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

+0

はありがとうございました、私の代わりに二つの別々のヘッダであることを私のヘッダ文を修正。編集を参照してください。生成されたファイルは正しいファイル名です。 – Vahe

関連する問題