Skip to content

Commit 409172c

Browse files
authored
Merge pull request #2416 from gamerlv/bugfix/GH1753-finfo-mimetype
Fix wrong mimetype for docx files
2 parents 6590189 + 9b8a84c commit 409172c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/PhpWord/Writer/Word2007.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ public function __construct(?PhpWord $phpWord = null)
5252
$this->setPhpWord($phpWord);
5353

5454
// Create parts
55+
// The first four files need to be in this order for Mimetype detection to work
5556
$this->parts = [
5657
'ContentTypes' => '[Content_Types].xml',
5758
'Rels' => '_rels/.rels',
59+
'RelsDocument' => 'word/_rels/document.xml.rels',
60+
'Document' => 'word/document.xml',
5861
'DocPropsApp' => 'docProps/app.xml',
5962
'DocPropsCore' => 'docProps/core.xml',
6063
'DocPropsCustom' => 'docProps/custom.xml',
61-
'RelsDocument' => 'word/_rels/document.xml.rels',
62-
'Document' => 'word/document.xml',
6364
'Comments' => 'word/comments.xml',
6465
'Styles' => 'word/styles.xml',
6566
'Numbering' => 'word/numbering.xml',

tests/PhpWordTests/Writer/Word2007Test.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpWordTests\Writer;
1919

20+
use finfo;
2021
use PhpOffice\PhpWord\PhpWord;
2122
use PhpOffice\PhpWord\SimpleType\Jc;
2223
use PhpOffice\PhpWord\Writer\Word2007;
@@ -192,4 +193,25 @@ public function testSetUseDiskCachingException(): void
192193
$object = new Word2007();
193194
$object->setUseDiskCaching(true, $dir);
194195
}
196+
197+
/**
198+
* File is detected as Word 2007.
199+
*/
200+
public function testMime(): void
201+
{
202+
$phpWord = new PhpWord();
203+
$section = $phpWord->addSection();
204+
$section->addText('Test 1');
205+
206+
$writer = new Word2007($phpWord);
207+
$file = __DIR__ . '/../_files/temp.docx';
208+
$writer->save($file);
209+
210+
$finfo = new finfo(FILEINFO_MIME_TYPE);
211+
$mime = $finfo->file($file);
212+
213+
self::assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', $mime);
214+
215+
unlink($file);
216+
}
195217
}

0 commit comments

Comments
 (0)