PhpWord mkdir(): Permission denied

185 views Asked by At

Hello I am trying to export a word document on Codeigniter project with XAMPP on mac but I cannot solve the permission problem. I know there are many similar questions but I try many things nothing helps. Here is my save method. When comment the headers part browser show me 4 Errors. Otherwise I can download the file but in text file same errors again printed.

public function saveWord()
{
    $phpWord = new \PhpOffice\PhpWord\PhpWord();
    $section = $phpWord->addSection();
    $section->addText('Hello World!');
    $file = 'HelloWorld.docx';
    // header("Content-Description: File Transfer");
    // header('Content-Disposition: attachment; filename="' . $file . '"');
    // 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');
    $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
    $xmlWriter->save("php://output");
}

1.Message: mkdir(): Permission denied

Filename: Writer/AbstractWriter.php

2.Message: tempnam(): file created in the system's temporary directory

Filename: Writer/AbstractWriter.php

3.Message: ZipArchive::close(): Failure to create temporary file: No such file or directory

Filename: Shared/ZipArchive.php

4.Type: PhpOffice\PhpWord\Exception\Exception

Message: Could not close zip file php://output:

Filename: /Applications/XAMPP/xamppfiles/htdocs/kvkkolay/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php

I also try to change folder owner with chown -R myusername:mygroup path/to/folder

for permission chmod -R 0777 path/to/folder

In addtion to I also check the php user with whoami the result is daemon.

In the source code of phpword I can see that they are trying to create a temp folder on this path /var/folders/45/zwgpkpmx3kj0hypypctn67rh0000gn/T/PHPWordWriter_635a3ef3f02cf5.54543358 also try to change this folder owner and permission but it returns not permitted.

Could any one help?

0

There are 0 answers