Welcome Guest, Not a member yet? Register   Sign In
Blank document when downloading word file just created.

(This post was last modified: 06-09-2016, 06:32 PM by Shawn.)

Using PHPWord I load a template from my public directory:
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(asset_url() . 'templates/receipt_template.docx');

I generate a file name and set headers for downloading the file:
$datetime = date('Y_M_d_G_i');
$filename = 'receipt_' . $datetime . '.docx';
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
I save the template as a new docx file (no changes for now) to the same directory. This works. I can see the new file in the public html directory and it has all the content of the template
$templateProcessor->saveAs(set_realpath('assets/templates/' . $filename));
This code downloads a word file, but the file is blank:
force_download(set_realpath('assets/templates/' . $filename, NULL, TRUE));
The above code resides in one controller. Is it a problem with opening a new filehandle before the other one is closed?

Messages In This Thread
Blank document when downloading word file just created. - by Shawn - 06-09-2016, 06:31 PM

Theme © iAndrew 2016 - Forum software by © MyBB