Skip to content

Commit

Permalink
fix mime type detection by finfo_file()
Browse files Browse the repository at this point in the history
When a MIME type was judged by finfo_file(), the MIME type of some file
types (Office, 7z, etc.) corrected the correctly unacquirable problem.
  • Loading branch information
nao-pon committed Apr 21, 2012
1 parent 8077b69 commit 299c73d
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 10 deletions.
42 changes: 36 additions & 6 deletions css/cwd.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,47 @@
.elfinder-cwd-icon-rtf,
.elfinder-cwd-icon-rtfd { background-position: 0 -401px; }
.elfinder-cwd-icon-pdf { background-position: 0 -450px; }
.elfinder-cwd-icon-vnd-ms-office,
.elfinder-cwd-icon-msword,
.elfinder-cwd-icon-vnd-ms-word,
.elfinder-cwd-icon-vnd-oasis-opendocument-text,
.elfinder-cwd-icon-ms-excel,
.elfinder-cwd-icon-msword,
.elfinder-cwd-icon-vnd-ms-excel,
.elfinder-cwd-icon-vnd-oasis-opendocument-spreadsheet,
.elfinder-cwd-icon-vnd-ms-excel-addin-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-excel-sheet-binary-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-excel-sheet-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-excel-template-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-office,
.elfinder-cwd-icon-vnd-ms-powerpoint,
.elfinder-cwd-icon-vnd-ms-powerpoint-addin-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-powerpoint-presentation-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-powerpoint-slide-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-powerpoint-slideshow-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-powerpoint-template-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-word,
.elfinder-cwd-icon-vnd-ms-word-document-macroEnabled-12,
.elfinder-cwd-icon-vnd-ms-word-template-macroEnabled-12,
.elfinder-cwd-icon-vnd-oasis-opendocument-chart,
.elfinder-cwd-icon-vnd-oasis-opendocument-database,
.elfinder-cwd-icon-vnd-oasis-opendocument-formula,
.elfinder-cwd-icon-vnd-oasis-opendocument-graphics,
.elfinder-cwd-icon-vnd-oasis-opendocument-graphics-template,
.elfinder-cwd-icon-vnd-oasis-opendocument-image,
.elfinder-cwd-icon-vnd-oasis-opendocument-presentation,
.elfinder-cwd-icon-vnd-oasis-opendocument-presentation-template,
.elfinder-cwd-icon-vnd-oasis-opendocument-spreadsheet,
.elfinder-cwd-icon-vnd-oasis-opendocument-spreadsheet-template,
.elfinder-cwd-icon-vnd-oasis-opendocument-text,
.elfinder-cwd-icon-vnd-oasis-opendocument-text-master,
.elfinder-cwd-icon-vnd-oasis-opendocument-text-template,
.elfinder-cwd-icon-vnd-oasis-opendocument-text-web,
.elfinder-cwd-icon-vnd-openofficeorg-extension,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-presentationml-presentation,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-presentationml-slide,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-presentationml-slideshow,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-presentationml-template,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-spreadsheetml-sheet
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-spreadsheetml-sheet,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-spreadsheetml-template,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-wordprocessingml-document,
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-spreadsheetml-sheet { background-position: 0 -500px; }
.elfinder-cwd-icon-vnd-openxmlformats-officedocument-wordprocessingml-template { background-position: 0 -500px; }
.elfinder-cwd-icon-html { background-position: 0 -550px; }
.elfinder-cwd-icon-css { background-position: 0 -600px; }
.elfinder-cwd-icon-javascript,
Expand Down
33 changes: 33 additions & 0 deletions js/elFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1727,11 +1727,44 @@ elFinder.prototype = {
'application/postscript' : 'Postscript',
'application/vnd.ms-office' : 'MsOffice',
'application/vnd.ms-word' : 'MsWord',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' : 'MsWord',
'application/vnd.ms-word.document.macroEnabled.12' : 'MsWord',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' : 'MsWord',
'application/vnd.ms-word.template.macroEnabled.12' : 'MsWord',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' : 'MsWord',
'application/vnd.ms-excel' : 'MsExcel',
'application/vnd.ms-excel.sheet.macroEnabled.12' : 'MsExcel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' : 'MsExcel',
'application/vnd.ms-excel.template.macroEnabled.12' : 'MsExcel',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12' : 'MsExcel',
'application/vnd.ms-excel.addin.macroEnabled.12' : 'MsExcel',
'application/vnd.ms-powerpoint' : 'MsPP',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' : 'MsPP',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12' : 'MsPP',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' : 'MsPP',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' : 'MsPP',
'application/vnd.openxmlformats-officedocument.presentationml.template' : 'MsPP',
'application/vnd.ms-powerpoint.template.macroEnabled.12' : 'MsPP',
'application/vnd.ms-powerpoint.addin.macroEnabled.12' : 'MsPP',
'application/vnd.openxmlformats-officedocument.presentationml.slide' : 'MsPP',
'application/vnd.ms-powerpoint.slide.macroEnabled.12' : 'MsPP',
'application/pdf' : 'PDF',
'application/xml' : 'XML',
'application/vnd.oasis.opendocument.text' : 'OO',
'application/vnd.oasis.opendocument.text-template' : 'OO',
'application/vnd.oasis.opendocument.text-web' : 'OO',
'application/vnd.oasis.opendocument.text-master' : 'OO',
'application/vnd.oasis.opendocument.graphics' : 'OO',
'application/vnd.oasis.opendocument.graphics-template' : 'OO',
'application/vnd.oasis.opendocument.presentation' : 'OO',
'application/vnd.oasis.opendocument.presentation-template' : 'OO',
'application/vnd.oasis.opendocument.spreadsheet' : 'OO',
'application/vnd.oasis.opendocument.spreadsheet-template' : 'OO',
'application/vnd.oasis.opendocument.chart' : 'OO',
'application/vnd.oasis.opendocument.formula' : 'OO',
'application/vnd.oasis.opendocument.database' : 'OO',
'application/vnd.oasis.opendocument.image' : 'OO',
'application/vnd.openofficeorg.extension' : 'OO',
'application/x-shockwave-flash' : 'AppFlash',
'application/flash-video' : 'Flash video',
'application/x-bittorrent' : 'Torrent',
Expand Down
49 changes: 45 additions & 4 deletions php/elFinderVolumeDriver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,45 @@ abstract class elFinderVolumeDriver {
'pps' => 'application/vnd.ms-powerpoint',
'pdf' => 'application/pdf',
'xml' => 'application/xml',
'odt' => 'application/vnd.oasis.opendocument.text',
'swf' => 'application/x-shockwave-flash',
'torrent' => 'application/x-bittorrent',
'jar' => 'application/x-jar',
// open office (finfo detect as application/zip)
'odt' => 'application/vnd.oasis.opendocument.text',
'ott' => 'application/vnd.oasis.opendocument.text-template',
'oth' => 'application/vnd.oasis.opendocument.text-web',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'odc' => 'application/vnd.oasis.opendocument.chart',
'odf' => 'application/vnd.oasis.opendocument.formula',
'odb' => 'application/vnd.oasis.opendocument.database',
'odi' => 'application/vnd.oasis.opendocument.image',
'oxt' => 'application/vnd.openofficeorg.extension',
// MS office 2007 (finfo detect as application/zip)
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
// archives
'gz' => 'application/x-gzip',
'tgz' => 'application/x-gzip',
Expand Down Expand Up @@ -1330,7 +1365,7 @@ public function upload($fp, $dst, $name, $tmpname) {
return $this->setError(elFinder::ERROR_INVALID_NAME);
}

$mime = $this->mimetype($this->mimeDetect == 'internal' ? $name : $tmpname);
$mime = $this->mimetype($this->mimeDetect == 'internal' ? $name : $tmpname, $name);
if ($mime == 'unknown' && $this->mimeDetect == 'internal') {
$mime = elFinderVolumeDriver::mimetypeInternalDetect($name);
}
Expand Down Expand Up @@ -2092,11 +2127,17 @@ protected function clearcache() {
* @return string
* @author Dmitry (dio) Levashov
**/
protected function mimetype($path) {
protected function mimetype($path, $name = '') {
$type = '';

if ($this->mimeDetect == 'finfo') {
$type = @finfo_file($this->finfo, $path);
if ($type = @finfo_file($this->finfo, $path)) {
if ($name === '') $name = $path;
$ext = (false === $pos = strrpos($name, '.')) ? '' : substr($name, $pos + 1);
if ($ext && preg_match('~^application/(?:octet-stream|(?:x-)?zip)~', $type)) {
if (isset(elFinderVolumeDriver::$mimetypes[$ext])) $type = elFinderVolumeDriver::$mimetypes[$ext];
}
}
} elseif ($type == 'mime_content_type') {
$type = mime_content_type($path);
} else {
Expand Down

0 comments on commit 299c73d

Please sign in to comment.