FAQ PHP

FAQ PHPConsultez toutes les FAQ
Nombre d'auteurs : 68, nombre de questions : 580, dernière mise à jour : 18 septembre 2021
Sommaire→Bibliothèques, extensions→XML→OpenXML (Microsoft Office)→Les Parts→Les types de contenu (ContentTypes)Voici comment créer un fichier Part pour un document Word (deux types par défaut + 1 type surchargé) :
<?php
$dom = new DOMDocument();
$XMLTypes = $dom->createElement('Types');
$XMLTypes->setAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
$dom->appendChild($XMLTypes);
$XMLType = $dom->createElement('Default');
$XMLType->setAttribute('Extension', 'rels');
$XMLType->setAttribute('ContentType', 'application/vnd.openxmlformats-package.relationships+xml');
$XMLTypes->appendChild($XMLType);
$XMLType = $dom->createElement('Default');
$XMLType->setAttribute('Extension', 'xml');
$XMLType->setAttribute('ContentType', 'application/xml');
$XMLTypes->appendChild($XMLType);
$XMLType = $dom->createElement('Override');
$XMLType->setAttribute('PartName', '/word/document.xml');
$XMLType->setAttribute('ContentType', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml');
$XMLTypes->appendChild($XMLType);
$dom->save('[Content_Types].xml');
?>La Part des types de contenu définit les types MIME de toutes les Parts de l'archive. Elle contient au moins quelques types par défaut, ainsi éventuellement que des types surchargés.
- "Extension" est l'extension du fichier, par exemple "xml", "png" ou "rels" ;
- "ContentType" est le type MIME du fichier, par exemple "application/xml", 'image/png" ou "application/vnd.openxmlformats-package.relationships+xml".
$XMLType = $dom->createElement('Default');
$XMLType->setAttribute('Extension', 'xml');
$XMLType->setAttribute('ContentType', 'application/xml');
$XMLTypes->appendChild($XMLType);Tous les fichiers d'une archive OpenXML n'ont pas toujours un type qui correspond à leur extension. Par exemple, la Part principale a généralement un type différent de "application/xml" malgré son extension "xml".
OpenXML prévoir la surcharge au cas par cas avec les Overrides. Il s'agit d'un élément Override dans le fichier [Content_Types].xml et contenant deux attributs PartName et ContentType.
- PartName : La Part concernée par la surcharge de type, par exemple "/word/document.xml" ;
- ContentType : Le nouveau type de la Part définie ci-dessus, par exemple "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml".
$XMLType = $dom->createElement('Override');
$XMLType->setAttribute('PartName', '/word/document.xml');
$XMLType->setAttribute('ContentType', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml');
$XMLTypes->appendChild($XMLType);- docm : application/vnd.ms-word.document.macroEnabled.12
- docx : application/vnd.openxmlformats-officedocument.wordprocessingml.document
- dotm : application/vnd.ms-word.template.macroEnabled.12
- dotx : application/vnd.openxmlformats-officedocument.wordprocessingml.template
- ppsm : application/vnd.ms-powerpoint.slideshow.macroEnabled.12
- ppsx : application/vnd.openxmlformats-officedocument.presentationml.slideshow
- pptm : application/vnd.ms-powerpoint.presentation.macroEnabled.12
- pptx : application/vnd.openxmlformats-officedocument.presentationml.presentation
- xlsb : application/vnd.ms-excel.sheet.binary.macroEnabled.12
- xlsm : application/vnd.ms-excel.sheet.macroEnabled.12
- xlsx : application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
- xps : application/vnd.ms-xpsdocument
Pour les images et autres documents dont le type MIME a été défini avant l'arrivée d'OpenXML, utilisez leur type MIME habituel.



