douzhuo2002 2016-10-28 10:22
浏览 301
已采纳

使PHPWord模板生成的文档自动下载而不是本地保存

PHPWord has an excellent template example but I checked its code and it saves the file locally (taken from ../Examples/Template.php):

$document = $PHPWord->loadTemplate('Template.docx');
...
$document->save('Solarsystem.docx');

Compared to one who uses the createWriter method which has an option to auto-download:

$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');

Is auto-download possible for templates? (see PHPWord/Template.php::save)

I do not want it to be saved locally to remove the task of creating a garbage collection when an auto-download option available.

  • 写回答

1条回答 默认 最新

  • dpz3471 2016-10-31 09:53
    关注

    I've used PHPWord's sample Sample_23_TemplateBlock.php to test this solution and it worked:

    // Add HTTP headers to force user's browser save document
    // instead of opening it like an HTML page
    header('Content-Type: application/octet-stream');
    header("Content-Disposition: attachment; filename=template.docx");
    
    // $templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx');
    $templateProcessor->saveAs('php://output');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度