Forum


Replies: 1   Views: 3025
Createdocxanddownload($filename) error with directories
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 Samuel  · 07-03-2017 - 09:11

Hi,

A call to createDocxAndDownload() with a filename that contains one or more directories will fail to download. I don't know if it's a bug or I'm using it incorrectly.

For example:

$docx->createDocxAndDownload('output/tmp/file.docx');

Generates the file in the correct path, but tries to download the file "file.docx" withouth the path, downloading a plain text file with the desired name (and extension) and a php error inside:

<p>Severity: Warning</p>
<p>Message:  filesize(): stat failed for file.docx</p>
<p>Filename: Create/CreateDocx.inc</p>
<p>Line Number: 3701</p>

Editing the file Classes/Phpdocx/Create/CreateDocx.inc, lines 3701 and 3702 solves my problem. From:

header('Content-Length: ' . filesize($fileNameDownload . '.' . $this->_extension));
readfile($fileNameDownload . '.' . $this->_extension);

To:

header('Content-Length: ' . filesize($args[0]));
readfile($args[0]);

More changes should be required as this edit breaks calls to createDocxAndDownload without the filename parameter.