0

I'm using PhpWord to save some data in Word format. The thing is that I need the user to select the place where it's needed to be saved. Right now I set it in the following way:

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

Is there any way to make the user select the location to store the document?

ZanattMan
  • 746
  • 1
  • 7
  • 26
  • 1
    that's definently beyond the scope of this site... you need to build a UI for selection, with a file browser, and store the result somehow (db/config file/local storage). When you try to save, retrieve and use it instead. – Nick Andriopoulos Apr 08 '13 at 15:43
  • @hexblot finaly it's easier than expected. Anyway, thanks for the help! – ZanattMan Apr 23 '13 at 13:08
  • the way you've worded the question made me think you meant saving the file on the server, hence the answer. Saving locally is handled by the browser, as you've shown. – Nick Andriopoulos Apr 23 '13 at 13:12

1 Answers1

1

I finally find the answer. It is possible if the document is stored in the server side end then you make the action of allowing the user to download it. The following code explain it:

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

Hope somebody can use it! :)

ZanattMan
  • 746
  • 1
  • 7
  • 26