D
D
Dmitry2016-08-02 14:30:54
Yii
Dmitry, 2016-08-02 14:30:54

What happens to the file, content substitution?

Good afternoon.
The problem is the following.
There is a site developed on yii2 framework.
Added functionality for uploading .docx, .odt files by the user. The file is uploaded to the server, read using PHPWord and the text from the file is written to the database. There are no errors at this moment.
Files, after the user uploads to the site, downloads the corrector to check for errors.
When you try to download a file to your computer, no errors occur, the file is downloaded. But if you open a file on a ms office or libre office computer (each file is opened by the corresponding program), then in the end we see the following.
e0f6c72d77a547aea8900a97741e2c70.png
ebfc9abab707402abeef945362be4b32.pnge127992a4c5f466192d0fd1c8ba94820.png
It looks like the file is being overwritten.
When testing a site on two local computers and on a third-party hosting, this does not happen. This error occurs only on the site where the working site is located.
Tell me, please, what could be the reason?
ps The problem arose recently, before that everything was fine. Could it be related to the server settings?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
PrAw, 2016-08-02
@slo_nik

If the downloaded file is renamed as .docx, then everything will work quite successfully (make sure). Either a smart browser incorrectly names names when downloading (see mimetype, as Denis Akimkin said ), or the file from the server is given with the wrong extension.
If the file is generated on the fly and served from php, then the coercion method is to give the file name with the extension right in the header:
header('Content-Disposition: attachment; filename="downloaded.docx"');
What exactly flew off - to look from the side of the hoster.
fix the correct answer - the wrong file began to contain UTF-8 BOM at the beginning of the file. Someone corrected the php script and saved it incorrectly in unicode.

M
Maxim Timofeev, 2016-08-02
@webinar

This is the encoding

D
Dmitry Skogorev, 2016-08-02
@EnterSandman

is
header('Content-Type: application/msword');
or
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question