【问题标题】:Select storing folder in client side在客户端选择存储文件夹
【发布时间】:2013-03-30 18:56:03
【问题描述】:

我正在使用 PhpWord 以 Word 格式保存一些数据。问题是我需要用户选择需要保存的位置。现在我用以下方式设置它:

$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$docName = '../../../files/generated_documents/document.docx';
$objWriter->save($docName);

有没有办法让用户选择存储文档的位置?

【问题讨论】:

  • 这绝对超出了本网站的范围......您需要使用文件浏览器构建一个用于选择的 UI,并以某种方式存储结果(db/config 文件/本地存储)。当您尝试保存、检索和使用它时。
  • @hexblot 最终它比预期的要容易。无论如何,感谢您的帮助!
  • 您提出问题的方式让我认为您的意思是将文件保存在服务器上,因此得到了答案。如您所示,本地保存由浏览器处理。

标签: php user-interaction phpword


【解决方案1】:

我终于找到了答案。如果文档存储在服务器端,那么您可以执行允许用户下载它的操作。下面的代码解释一下:

$docName = 'document.doc';
$docPath = 'path/inThe/server/';
$fullName= $docPath.$docName;
$objWriter->save($fullName);
$this->downloadTimeSheetFile($docName,$docPath);


header('Content-type: application/doc');
header('Content-Disposition: attachment; filename="'.$docName.'"');
readfile($fullName);

希望有人可以使用它! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 2018-03-05
    • 2021-10-07
    相关资源
    最近更新 更多