Forum


Replies: 5   Views: 2099
How do i create a docx in the output of php by sending the user agent to download it ?
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 anjanesh  · 07-03-2016 - 09:26

Im trying to create a docx file on the fly using PHP.

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=plan.docx");
header("Content-type: application/octet-stream");
header("Content-Transfer-Encoding: binary");

require_once 'phpdocx-trial-pro-5.5/classes/CreateDocx.inc';
$docx = new CreateDocx();
...
$docx->createDocx('plan'); # How do I output the contents to the file being downloaded instead of writing to a file ?

 

Posted by admin  · 07-03-2016 - 09:37

Hello,

You always need to generate the DOCX file in the fs. Using the createDocxAndDownload method you can generate and download the document, but if you don't want to keep the document you must remove it using the unlink function from PHP.

Regards.

Posted by anjanesh  · 07-03-2016 - 10:31

Ok. Thanks. But now, its spitting an error. Unfortunately, I have to use __autoload() in my code. Is there a way to hide this error and still download ?

Warning: log4php: It looks like your code is using an __autoload() function. log4php uses spl_autoload_register() which will bypass your __autoload() function and may break autoloading. in /home/username/www/3rdParty/phpdocx-trial-pro-5.5/lib/log4php/LoggerAutoloader.php on line 22

Posted by admin  · 07-03-2016 - 11:07

Hello,

Sorry but trial package doesn't include support and as it's crypted it can't be debugged. Anyway a warning message can be easily removed using your own PHP code.

We recommend you to use the library standalone to test it, and purchase a license to integrate it in your project.

Regards.

Posted by anjanesh  · 07-03-2016 - 11:16

Yes, I'll buy the license once I get the basics working on my project with the trial.

For now, I need to know how to get this working.

Im getting the error :

Warning: require_once(/path/to/my/project/classes/CreateDocument.php): failed to open stream: No such file or directory in /path/to/my/project/global.lib.php on line 33

Fatal error: require_once(): Failed opening required '/path/to/my/project/classes/CreateDocument.php' (include_path='.:/usr/share/php:/usr/share/pear') in /path/to/my/project/global.lib.php on line 33

Problem is, its looking for the class in my spl_autoload_register('my_autoloader');

spl_autoload_register('my_autoloader');
function my_autoloader($className)
{    
    # echo $className."\n";

    ....


    if (!empty($filename))
    {
        require_once $filename; // line 33
    }
}

 

Posted by admin  · 07-03-2016 - 11:24

Hello,

Sorry but trial package doesn't include support and as it's crypted it can't be debugged. We recommend you to use the library standalone to test it.

Regards.