Skip to content
Snippets Groups Projects
Commit f54a01e0 authored by Prasad's avatar Prasad
Browse files

Added vtlib_mime_content_type API that works with mime_magic or file info php extension.

parent c1604204
No related branches found
No related tags found
No related merge requests found
......@@ -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
?>
......@@ -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);
}
?>
......@@ -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
}
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment