如何修改以下脚本(Summary.php),以便服务的PPTX文件名不是" Summary.php"我的服务文件名为Summary.php.pptx?
我使用的技术是将PowerPoint文件的内容呈现到浏览器中,但我有意将文件名更改为至少不包含.php,但最好是自定义名称,如Presentation.pptx中指定的我的php标题如下。
Summary.php
txtValue = ListView1.SelectedItems(0).SubItems(1).Text
txtValue1 = ListView1.SelectedItems(0).SubItems(2).Text
修改
解决方案
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');
}
}
答案 0 :(得分:1)
您应该使用Content-Disposition
响应标头。 E.g。
Content-Disposition: attachment; filename="filename.jpg"
参考:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition