Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phpword loadTemplate() finction behave differently on php thread safe and php non thread safe #1149

Closed
kidzen opened this issue Sep 29, 2017 · 3 comments

Comments

@kidzen
Copy link

kidzen commented Sep 29, 2017

How to replicate error:

Use phpword loadTemplate function..
$object = new/phpoffice/phpword/phpword()->loadTemplate('template.docx');

Error:
ZipArchive::getFromName():invalid or uninitialized zip object

@FBnil
Copy link

FBnil commented Sep 29, 2017

I get a syntax error with that. Can you give also the configuration information?
Which version of PHP, which OS, which PHP add-ons you are using (like fcgi), which frontend (hiawatha/apache/etc). I assume PHPWord is at 0.13?

	($object = new \PhpOffice\PhpWord\PhpWord())->loadTemplate('template.docx');
	$object->save(storage_path('y.docx'));
	return response()->download(storage_path('y.docx'))->deleteFileAfterSend(true);   

@kidzen
Copy link
Author

kidzen commented Sep 30, 2017

@FBnil im currently running PHP 7.1 with IIS as web server..
try this..

$object = new \PhpOffice\PhpWord\PhpWord();
$object->loadTemplate('template.docx');
$object->save(storage_path('y.docx'));
return response()->download(storage_path('y.docx'))->deleteFileAfterSend(true);

@kidzen
Copy link
Author

kidzen commented Sep 30, 2017

By the way, turn out that this issue related to permission when PhpOffice try to create a temp file inside windows default temporary directory (C:/windows/Temp )..

My suggestion, by default Settings:getTempDir() should return webroot path instead of windows/Server Temp Directory.

public static function getTempDir()
{
     $tempDir = sys_get_temp_dir();      <----the culprit
     if (!empty(self::$tempDir)) {
          $tempDir = self::$tempDir;
     }
     return $tempDir;
}

@kidzen kidzen closed this as completed Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants