Forum


Replies: 3   Views: 3928
Createdocxanddownload bug
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 02-08-2016 - 18:10

Hello,

The method createDocxAndDownload creates and downloads the DOCX but it doesn't remove the file. If you need to remove it after being created, we recommend you to use the function unlink (http://php.net/manual/en/function.unlink.php)

About downloading name, this method just calls createDocx to generate the document and uses these lines to download it:

header(
    'Content-Type: application/vnd.openxmlformats-officedocument.' .
    'wordprocessingml.document'
);
header(
    'Content-Disposition: attachment; filename="' . $fileNameDownload .
    '.' . $this->_extension . '"'
);
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($fileName . '.' . $this->_extension));
readfile($fileName . '.' . $this->_extension);

It's a generic method to download a DOCX. If it doesn't fit your needs or it's not working on your server (some server may require additional lines to download the DOCX properly), we recommend you to use the method createDocx directly and then download it using your code, for example setting a random name in this line:

header(
  'Content-Disposition: attachment; filename="' . $fileNameDownload . '.' . $this->_extension . '"'
);

Regards.