|
Cookbook /
UploadTypesSummary: Add extensions to or remove them from the list of allowed upload types
Version: n/a
Prerequisites:
Status: Documentation
Maintainer:
Categories: Uploads
Questions answered by this recipeHow can I add/remove extensions to/from the list of allowed upload types? AnswerAdding new file types to permitted uploadsTo add a new extension to the list of allowed upload types, add a line like the following to a local customization file: $UploadExts['ext'] = 'content-type';
where ext is the extension to be added, and content-type is the "MIME type", or content-type (which you may find here or on the lower part of this page) to be used for files with that extension. For example, to add the ' $UploadExts['dxf'] = 'image/x-dxf';
Each entry in $UploadExts needs to be the extension and the mime-type associated with that extension, thus: $UploadExts = array( 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'xxx' => 'yyyy/zzz' ); For the types that PmWiki already knows about it's not necessary to repeat them here (the upload.php script adds PmWiki's defaults to whatever the administrator supplies). Restricting uploaded files type and sizeThe upload script performs a number of verifications on an uploaded file before storing it in the upload directory. The basic verifications are described below.
$UploadMaxSize = 100000;
However, the default maximum file size can also be specified for each type of file uploaded. Thus, an administrator can restrict " $UploadExtSize['gif'] = 20000; # limit .gif files to 20KB
ExamplesThese examples are provided to save you the effort have having to repeat the MIME type research $UploadExts['dot'] = 'application/msword'; # Document template $UploadExts['iso'] = 'application/octetstream'; # CD Disc image $UploadExts['svg'] = 'image/svg+xml'; # Scalable Vector Graphic (in default list) content - MIME types for Office 2007 files[1] [2] $UploadExts['docm'] = 'application/vnd.ms-word.document.macroEnabled.12'; # $UploadExts['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; # Word document $UploadExts['dotm'] = 'application/vnd.ms-word.template.macroEnabled.12'; # $UploadExts['dotx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'; # Word document template $UploadExts['potm'] = 'application/vnd.ms-powerpoint.template.macroEnabled.12'; # $UploadExts['potx'] = 'application/vnd.openxmlformats-officedocument.presentationml.template'; # Presentation template $UploadExts['ppam'] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12'; # $UploadExts['ppsm'] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'; # $UploadExts['ppsx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'; # Presentation sideshow $UploadExts['pptm'] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'; # $UploadExts['pptx'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; # Presentation $UploadExts['xlam'] = 'application/vnd.ms-excel.addin.macroEnabled.12'; # $UploadExts['xlsb'] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'; # $UploadExts['xlsm'] = 'application/vnd.ms-excel.sheet.macroEnabled.12'; # $UploadExts['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; # Spreadsheet $UploadExts['xltm'] = 'application/vnd.ms-excel.template.macroEnabled.12'; # $UploadExts['xltx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; # Spreadsheet template To permit the uploading of OpenOffice.org files, you should add the following lines to your local customization file: $UploadExts['odb'] = 'application/vnd.oasis.opendocument.database'; $UploadExts['odc'] = 'application/vnd.oasis.opendocument.chart'; $UploadExts['odf'] = 'application/vnd.oasis.opendocument.formula'; $UploadExts['odg'] = 'application/vnd.oasis.opendocument.graphics'; $UploadExts['odm'] = 'application/vnd.oasis.opendocument.text-master'; $UploadExts['odp'] = 'application/vnd.oasis.opendocument.presentation'; $UploadExts['odp'] = 'application/vnd.oasis.opendocument.presentation'; $UploadExts['ods'] = 'application/vnd.oasis.opendocument.spreadsheet'; $UploadExts['odt'] = 'application/vnd.oasis.opendocument.text'; $UploadExts['otg'] = 'application/vnd.oasis.opendocument.graphics-template'; $UploadExts['oth'] = 'application/vnd.oasis.opendocument.text-web'; $UploadExts['otp'] = 'application/vnd.oasis.opendocument.presentation-template'; $UploadExts['ots'] = 'application/vnd.oasis.opendocument.spreadsheet-template'; $UploadExts['ott'] = 'application/vnd.oasis.opendocument.text-template'; $UploadExts['sda'] = 'application/vnd.stardivision.draw'; $UploadExts['sdc'] = 'application/vnd.stardivision.calc'; $UploadExts['sdd'] = 'application/vnd.stardivision.impress'; $UploadExts['sdf'] = 'application/vnd.stardivision.math'; $UploadExts['sds'] = 'application/vnd.stardivision.chart'; $UploadExts['sdw'] = 'application/vnd.stardivision.writer'; $UploadExts['sgl'] = 'application/vnd.stardivision.writer-global'; See links for more instructions specific to windows IIS and Apache
Discussion
Check out this page or, on a Linux/Unix system, use the 'file' command with the --mime option: file --mime filename
$UploadExtSize[''] = 0; # disallow no extension files
To my knowledge there is no built in functionality, or recipe that does this. But see Cookbook:Attachtable. simon March 17, 2010, at 02:57 PM
See also
Contributors
User notes +2: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |