Forum


Replies: 7   Views: 4218
Permission denied when trying to delete the last merged file
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 Bouillou  · 12-05-2015 - 08:04

Here is a simple script to reproduce the problem : // Issue : the last merged file cannot be deleted require_once '../../../Classes/Phpdocx/Create/CreateDocx.inc'; $docx = new Phpdocx\Create\CreateDocxFromTemplate('testVAR.docx'); $docx->replaceVariableByText(array('VAR1' => 'OK1')); $docx->replaceVariableByText(array('VAR2' => 'OK2')); $docx->createDocx('out1'); $docx = new Phpdocx\Create\CreateDocxFromTemplate('testVAR.docx'); $docx->replaceVariableByText(array('VAR1' => 'OK1')); $docx->replaceVariableByText(array('VAR2' => 'OK2')); $docx->createDocx('out2'); $docx = new Phpdocx\Create\CreateDocxFromTemplate('testVAR.docx'); $docx->replaceVariableByText(array('VAR1' => 'OK1')); $docx->replaceVariableByText(array('VAR2' => 'OK2')); $docx->createDocx('out3'); $merge = new Phpdocx\BatchProcessing\MultiMerge(); $merge->mergeDocx('out1.docx', array('out2.docx', 'out3.docx'), 'out_final.docx', array()); unlink('out1.docx'); unlink('out2.docx'); // this file cannot be deleted : PHP Warning: unlink(out3.docx): Permission denied unlink('out3.docx'); // Test with one file to merge $merge = new Phpdocx\BatchProcessing\MultiMerge(); $merge->mergeDocx('out1.docx', array('out2.docx'), 'out_final.docx', array()); unlink('out1.docx'); // this file cannot be deleted : PHP Warning: unlink(out2.docx): Permission denied unlink('out2.docx');

Posted by admin  · 12-05-2015 - 12:10

Hello, The rwx access of the files is not defined by phpdocx but by your server. Please check the default rw access, the umask and the PHP user that is creating the documents. Regards.

Posted by Bouillou  · 12-05-2015 - 13:16

Thanks for your anwer. Have a look on my code, the files are created by PHPDocX. Therefore, there is no reason that PHPDocX cannot delete it. I can send you a script to test the code if you want.

Posted by admin  · 12-05-2015 - 14:04

Hello, Please post the full access of that files. This is to run $ ls -alrt of the files. Regards.

Posted by Bouillou  · 13-05-2015 - 11:05

Actually, it is working on Linux, but not on Windows. Best regards

Posted by admin  · 13-05-2015 - 11:58

Hello, Then please post the file permissions using the Windows tool. We recommend you to run the same script using the PHP CLI mode to check if the problem is with PHP or the web server. Regards.

Posted by lolocava  · 02-07-2015 - 08:08

Hello, I Have the same problem. Permission denied when I try to unlink the last merged file. I set the chmod on file and folder before. Best regards.

Posted by Many  · 21-09-2015 - 13:04

I had the same problem and fixed it by looking into the docx library. In phpdocx\classes\MultiMerge.inc there is an foreach loop for $documentArray as $key => $secondDocument. In this loop each file is opened, but never closed. So I added the following line "$this->_secondDocx->close();" at the end of the loop, and the last file in the array was deleted when using the unlink function.