Replies: 6   Views: 2566
Set temp_path from code
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 jhanley  · 30-10-2019 - 19:23

Thanks for your latest reply and continued support.

As you suspected, I am using CreateDocxFromTemplate() to create the DOCX file and createDocxAndDownload() to deliver the document immediately for download. I do not need or desire to save the documents on the server.

To answer your first question. The generated DOCX file is being saved in the webroot.

Here's the runtime error message logged on production:

Warning: ZipArchive::close(): Failure to create temporary file: Permission denied in Phpdocx\Utilities\DOCXStructure->saveDocx() 

When the "permission denied" error occurs on production, the download DOCX file is completely empty.

To answer your next question, sys_get_temp_dir() returns "/tmp" both locally and production. However, Acquia prevents the usage of "/tmp" and instead says to use "/mnt/tmp/[sitename].[env]".

Acquia is the biggest Drupal hosting service around so compatbility with their environment is essential.

I would prefer not to mess with php.ini.

Ideally, I would like to use a custom directory as the temporary directory. In Drupal this is commonly "sites/default/files".

Again, I tried assigning "temp_path" the absolute server path to the "files" directory, but the setting is seemingly ignored by CreateDocxFromTemplate().

That said, what do you recommend to resolve this "permission denied" and temporary directory issue?