From 3f42ca11e752696d9aaafe9b006d8e0f07136928 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 16 Jun 2012 22:05:07 -0400 Subject: Fixes #4079 detecting docx, xlsx, and pptx files in file plugin --- mod/file/actions/file/upload.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'mod/file/actions/file/upload.php') diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php index 5242cbda2..d72d04eb7 100644 --- a/mod/file/actions/file/upload.php +++ b/mod/file/actions/file/upload.php @@ -94,8 +94,31 @@ if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $filestorename = elgg_strtolower(time().$_FILES['upload']['name']); } - $mime_type = $file->detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']); $file->setFilename($prefix . $filestorename); + $mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']); + + // hack for Microsoft zipped formats + $info = pathinfo($_FILES['upload']['name']); + $office_formats = array('docx', 'xlsx', 'pptx'); + if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) { + switch ($info['extension']) { + case 'docx': + $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; + break; + case 'xlsx': + $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + break; + case 'pptx': + $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; + break; + } + } + + // check for bad ppt detection + if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") { + $mime_type = "application/vnd.ms-powerpoint"; + } + $file->setMimeType($mime_type); $file->originalfilename = $_FILES['upload']['name']; $file->simpletype = file_get_simple_type($mime_type); -- cgit v1.2.3