From f54a01e0415389af1a98d2a1b7ad4f4229a27201 Mon Sep 17 00:00:00 2001 From: prasad <prasad@vtiger.com> Date: Thu, 22 Oct 2015 09:26:25 +0530 Subject: [PATCH] Added vtlib_mime_content_type API that works with mime_magic or file info php extension. --- data/CRMEntity.php | 4 ++-- include/utils/VtlibUtils.php | 4 ++++ .../Vtiger/actions/CompanyDetailsSave.php | 4 ++-- vtlib/Vtiger/Functions.php | 21 +++++++++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/data/CRMEntity.php b/data/CRMEntity.php index 5ecd1526..10a83cad 100755 --- a/data/CRMEntity.php +++ b/data/CRMEntity.php @@ -139,7 +139,7 @@ class CRMEntity { $save_file = 'true'; //only images are allowed for Image Attachmenttype - $mimeType = mime_content_type($file_details['tmp_name']); + $mimeType = vtlib_mime_content_type($file_details['tmp_name']); $mimeTypeContents = explode('/', $mimeType); // For contacts and products we are sending attachmentType as value if ($attachmentType == 'Image' || ($file_details['size'] && $mimeTypeContents[0] == 'image')) { @@ -2696,4 +2696,4 @@ class CRMEntity { return $query; } } -?> \ No newline at end of file +?> diff --git a/include/utils/VtlibUtils.php b/include/utils/VtlibUtils.php index 096ba474..24a0bfc9 100644 --- a/include/utils/VtlibUtils.php +++ b/include/utils/VtlibUtils.php @@ -704,4 +704,8 @@ function vtlib_module_icon($modulename){ return "modules/Vtiger/Vtiger.png"; } +function vtlib_mime_content_type($filename) { + return Vtiger_Functions::mime_content_type($filename); +} + ?> diff --git a/modules/Settings/Vtiger/actions/CompanyDetailsSave.php b/modules/Settings/Vtiger/actions/CompanyDetailsSave.php index 28da624c..676e22bc 100644 --- a/modules/Settings/Vtiger/actions/CompanyDetailsSave.php +++ b/modules/Settings/Vtiger/actions/CompanyDetailsSave.php @@ -28,7 +28,7 @@ class Settings_Vtiger_CompanyDetailsSave_Action extends Settings_Vtiger_Basic_Ac } //mime type check - $mimeType = mime_content_type($logoDetails['tmp_name']); + $mimeType = vtlib_mime_content_type($logoDetails['tmp_name']); $mimeTypeContents = explode('/', $mimeType); if (!$logoDetails['size'] || $mimeTypeContents[0] != 'image' || !in_array($mimeTypeContents[1], Settings_Vtiger_CompanyDetails_Model::$logoSupportedFormats)) { $saveLogo = false; @@ -73,4 +73,4 @@ class Settings_Vtiger_CompanyDetailsSave_Action extends Settings_Vtiger_Basic_Ac public function validateRequest(Vtiger_Request $request) { $request->validateWriteAccess(); } -} \ No newline at end of file +} diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php index 7b7c2abf..e0c3aace 100644 --- a/vtlib/Vtiger/Functions.php +++ b/vtlib/Vtiger/Functions.php @@ -938,7 +938,24 @@ class Vtiger_Functions { $noof_group_rows = $adb->num_rows($result); return $result; } - + + /** + * Function to determine mime type of file. + * Compatible with mime_magic or fileinfo php extension. + */ + static function mime_content_type($filename) { + $type = null; + if (function_exists('mime_content_type')) { + $type = mime_content_type($filename); + } else if (function_exists('finfo_open')) { + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $type = finfo_file($finfo, $filename); + finfo_close($finfo); + } else { + throw new Exception('mime_magic or fileinfo extension required.'); + } + return $type; + } /** * Check the file MIME Type @@ -946,7 +963,7 @@ class Vtiger_Functions { * @param $claimedMime Array of bad file extenstions */ static function verifyClaimedMIME($targetFile,$claimedMime) { - $fileMimeContentType= mime_content_type($targetFile); + $fileMimeContentType= self::mime_content_type($targetFile); if (in_array(strtolower($fileMimeContentType), $claimedMime)) { return false; } -- GitLab