![]() |
Blank document when downloading word file just created. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7) +--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13) +--- Thread: Blank document when downloading word file just created. (/showthread.php?tid=65421) |
Blank document when downloading word file just created. - Shawn - 06-09-2016 Using PHPWord I load a template from my public directory: Code: $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(asset_url() . 'templates/receipt_template.docx'); I generate a file name and set headers for downloading the file: Code: $datetime = date('Y_M_d_G_i'); Code: $templateProcessor->saveAs(set_realpath('assets/templates/' . $filename)); Code: force_download(set_realpath('assets/templates/' . $filename, NULL, TRUE)); RE: Blank document when downloading word file just created. - InsiteFX - 06-10-2016 If a file is open it cannot be modified. RE: Blank document when downloading word file just created. - Shawn - 06-10-2016 (06-10-2016, 04:18 AM)InsiteFX Wrote: If a file is open it cannot be modified. How do I ensure that the file has been closed after the TemplateProcessor->saveAs statement, before attempting the force_download? RE: Blank document when downloading word file just created. - Shawn - 06-14-2016 This is the solution I arrived at: I created as directory structure at the same level of the application and system directory (outside the public html) assets\templates\receipt_template.docx assets\receipts\ In my model: Code: // delete any previous files created and downloaded, first |