Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to upload PhpWord generated file to server in Yii2?
The uploaded file UploadedFile() does not pass validation for the docx extension.
public function rules()
{
return [
[['imageFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'pdf, png, jpg, docx'],
];
}
Yii::trace($this->imageFile->extension);
Yii::trace(FileHelper::getMimeType($this->imageFile));
docx
andapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
respectively, and givesYii::trace($this->getErrors());
[
'imageFile' => [
'Only files with these extensions are allowed: pdf, png, jpg, docx.',
],
]
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Are you talking about PHPOffice/PHPWord?
If yes, then I also had a similar problem with docx when I tried to deal with this library. I did not solve the problem, most likely because of the problems of the file structure.
Try adding doc to the validation condition, maybe it will work.
If you use LibreOffice, then there are no problems, as far as I remember))) Generates odt well and reads well.
ps The library itself is rather damp, I remember that I was modifying something there to work with tables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question