Index: inc/document.class.php =================================================================== --- inc/document.class.php (révision 23462) +++ inc/document.class.php (copie de travail) @@ -906,15 +906,8 @@ } // Local file : try to detect mime type - if (function_exists('finfo_open') - && ($finfo = finfo_open(FILEINFO_MIME))) { - $input['mime'] = finfo_file($finfo, $fullpath); - finfo_close($finfo); + $input['mime'] = Toolbox::getMime($fullpath); - } else if (function_exists('mime_content_type')) { - $input['mime'] = mime_content_type($fullpath); - } - if (is_writable(GLPI_UPLOAD_DIR) && is_writable ($fullpath)) { // Move if allowed Index: inc/ticket.class.php =================================================================== --- inc/ticket.class.php (révision 23462) +++ inc/ticket.class.php (copie de travail) @@ -5576,19 +5576,8 @@ $mime = ''; if (isset($image['filepath'])) { $fullpath = GLPI_DOC_DIR."/".$image['filepath']; - if (function_exists('finfo_open') - && ($finfo = finfo_open(FILEINFO_MIME))) { - $mime = finfo_file($finfo, $fullpath); - finfo_close($finfo); - - } else if (function_exists('mime_content_type')) { - $mime = mime_content_type($fullpath); - } - switch (substr($mime, 0, strrpos($mime, ';'))) { - case 'image/gif':case 'image/jpg':case 'image/jpeg':case 'image/png' : - $ok = true; - break; - } + $mime = Toolbox::getMime($fullpath); + $ok = Toolbox::getMime($fullpath, 'image'); } if (isset($image['tag'])) { if ($ok || empty($mime)) { Index: inc/toolbox.class.php =================================================================== --- inc/toolbox.class.php (révision 23462) +++ inc/toolbox.class.php (copie de travail) @@ -976,6 +976,21 @@ } echo ""; + // Test for fileinfo extension loaded or not + echo "".__('Test fileinfo extension').""; + + if (!class_exists('finfo')) { + echo "". + __("GLPI can't work correctly without the fileinfo extension").""; + $error = 2; + + } else { + echo "\""."; + } + echo ""; + // Test for json_encode function. echo "".__('Test json functions').""; @@ -982,7 +997,7 @@ if (!function_exists('json_encode') || !function_exists('json_decode')) { echo "". __("GLPI can't work correctly without the json_encode and json_decode functions"). - ">"; + ""; $error = 2; } else { @@ -2435,6 +2450,30 @@ return false; } + /** + * Retrieve the mime type of a file + * + * @since version 0.85.4 + * + * @param $file string path of the file + * @param $type string check if $file is the correct type + * + * @return string (if $type not given) else boolean + * + **/ + static function getMime($file, $type=false) { + static $finfo = NULL; + if (is_null($finfo)) { + $finfo = new finfo(FILEINFO_MIME_TYPE); + } + $mime = $finfo->file($file); + Toolbox::logdebug($file, $mime, explode('/', $mime, 2)); + if ($type) { + $parts = explode('/', $mime, 2); + return ($parts[0] == $type); + } + return ($mime); + } } ?> Index: inc/user.class.php =================================================================== --- inc/user.class.php (révision 23462) +++ inc/user.class.php (copie de travail) @@ -670,8 +670,7 @@ } } else { - $mime = mime_content_type($_FILES['picture']['tmp_name']); - if (strstr($mime,'image')!==false) { + if (toolbox::getMime($_FILES['picture']['tmp_name'], 'image')) { // Unlink old picture (clean on changing format) self::dropPictureFiles($this->fields['picture']);