Задать вопрос
@kickass77

Почему не работает PHPWord?

<?
require_once('vendor/autoload.php');

$document = new \PhpOffice\PhpWord\TemplateProcessor('./file.docx');

$uploadDir = __DIR__;
$outputFile = 'new_file.docx';

$name = "22222222";
$document->setValue('name', $name);

$document->saveAs($outputFile);
?>


В файл вместо ${name} должно было указаться значение 22222222
Файл в принципе не создается.
Ошибка:

Fatal error: Uncaught PhpOffice\PhpWord\Exception\CreateTemporaryFileException: Could not create a temporary file with unique name in the specified directory. in /var/www/a/data/www/t/include/PHPWord/vendor/phpoffice/phpword/src/PhpWord/TemplateProcessor.php:108 Stack trace: #0 /var/www/a/data/www/t/include/PHPWord/test.php(4): PhpOffice\PhpWord\TemplateProcessor->__construct('./artist.docx') #1 {main} thrown in /var/www/a/data/www/t/include/PHPWord/vendor/phpoffice/phpword/src/PhpWord/TemplateProcessor.php on line 108
  • Вопрос задан
  • 338 просмотров
Подписаться 1 Сложный 1 комментарий
Пригласить эксперта
Ответы на вопрос 1
@entermix
Hi, did you found a solution for this problem?

upd:
Well, after hours of attempts I fixed it:
There could be few reasons:

Not enought permissions on operation folder (you need to put recousively 775 permission to make it work)

Check the owner and owner-group of this folder, maybe current user doesn't have permission to read/write in current folder, also could be fixed by providing extra permissions to folder (777)

Check your tmp folder, if it's also writable or not. In internet there are a lot of variants how to do it, in my case, I have just change path to tmp folder in vendor/phpoffice/phpword/src/Settings.php, function getTempDir(), I have hardcoded absolute path of current working directory and problem was gone. But probably it's not best idea.


https://github.com/PHPOffice/PHPWord/issues/809
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы