选择在客户端存储文件夹

时间:2013-04-08 15:41:42

标签: php user-interaction phpword

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

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

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

1 个答案:

答案 0 :(得分: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);

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