[[+content_image]]
U
U
ukoHka2017-09-22 07:13:05
Yii
ukoHka, 2017-09-22 07:13:05

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'],
        ];
    }

Wherein
Yii::trace($this->imageFile->extension);
Yii::trace(FileHelper::getMimeType($this->imageFile));

issue docxand
application/vnd.openxmlformats-officedocument.wordprocessingml.document
respectively, and givesYii::trace($this->getErrors());
[
    'imageFile' => [
        'Only files with these extensions are allowed: pdf, png, jpg, docx.',
    ],
]

Here they write that the mime-type is being checked, but the correct mime-type is displayed.
If you save the file in MS Word as Strict docx, the file passes the check.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dmitry, 2017-09-22
@slo_nik

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 question

Ask a Question

731 491 924 answers to any question