mime.patch

remi, 04/23/2015 07:51 PM

Download (4.56 KB)

View differences:

inc/document.class.php (copie de travail)
906 906
      }
907 907

  
908 908
      // Local file : try to detect mime type
909
      if (function_exists('finfo_open')
910
          && ($finfo = finfo_open(FILEINFO_MIME))) {
911
         $input['mime'] = finfo_file($finfo, $fullpath);
912
         finfo_close($finfo);
909
      $input['mime'] = Toolbox::getMime($fullpath);
913 910

  
914
      } else if (function_exists('mime_content_type')) {
915
         $input['mime'] = mime_content_type($fullpath);
916
      }
917

  
918 911
      if (is_writable(GLPI_UPLOAD_DIR)
919 912
          && is_writable ($fullpath)) { // Move if allowed
920 913

  
inc/ticket.class.php (copie de travail)
5576 5576
            $mime     = '';
5577 5577
            if (isset($image['filepath'])) {
5578 5578
               $fullpath = GLPI_DOC_DIR."/".$image['filepath'];
5579
               if (function_exists('finfo_open')
5580
                   && ($finfo = finfo_open(FILEINFO_MIME))) {
5581
                  $mime = finfo_file($finfo, $fullpath);
5582
                  finfo_close($finfo);
5583

  
5584
               } else if (function_exists('mime_content_type')) {
5585
                  $mime = mime_content_type($fullpath);
5586
               }
5587
               switch (substr($mime, 0, strrpos($mime, ';'))) {
5588
                  case 'image/gif':case 'image/jpg':case 'image/jpeg':case 'image/png' :
5589
                     $ok = true;
5590
                     break;
5591
               }
5579
               $mime = Toolbox::getMime($fullpath);
5580
               $ok   = Toolbox::getMime($fullpath, 'image');
5592 5581
            }
5593 5582
            if (isset($image['tag'])) {
5594 5583
                if ($ok || empty($mime)) {
inc/toolbox.class.php (copie de travail)
976 976
      }
977 977
      echo "</tr>";
978 978

  
979
      // Test for fileinfo extension loaded or not
980
      echo "<tr class='tab_bg_1'><td class='left b'>".__('Test fileinfo extension')."</td>";
981

  
982
      if (!class_exists('finfo')) {
983
         echo "<td><img src='".$CFG_GLPI['root_doc']."/pics/redbutton.png'>".
984
                    __("GLPI can't work correctly without the fileinfo extension")."</td>";
985
         $error = 2;
986

  
987
      } else {
988
         echo "<td><img src='".$CFG_GLPI['root_doc']."/pics/greenbutton.png' alt=\"".
989
                    __s('The functionality is found - Perfect!')."\" title=\"".
990
                    __s('The functionality is found - Perfect!')."\"></td>";
991
      }
992
      echo "</tr>";
993

  
979 994
      // Test for json_encode function.
980 995
      echo "<tr class='tab_bg_1'><td class='left b'>".__('Test json functions')."</td>";
981 996

  
982 997
      if (!function_exists('json_encode') || !function_exists('json_decode')) {
983 998
         echo "<td><img src='".$CFG_GLPI['root_doc']."/pics/redbutton.png'>".
984 999
                    __("GLPI can't work correctly without the json_encode and json_decode functions").
985
                   "></td>";
1000
                   "</td>";
986 1001
         $error = 2;
987 1002

  
988 1003
      } else {
......
2435 2450
      return false;
2436 2451
   }
2437 2452

  
2453
   /**
2454
    * Retrieve the mime type of a file
2455
    * 
2456
    * @since version 0.85.4
2457
    *
2458
    * @param $file   string      path of the file
2459
    * @param $type   string      check if $file is the correct type     
2460
    *
2461
    * @return string (if $type not given) else boolean
2462
    *
2463
   **/
2464
   static function getMime($file, $type=false) {
2465
      static $finfo = NULL;
2438 2466

  
2467
      if (is_null($finfo)) {
2468
         $finfo = new finfo(FILEINFO_MIME_TYPE);
2469
      }
2470
      $mime = $finfo->file($file);
2471
      Toolbox::logdebug($file, $mime, explode('/', $mime, 2));
2472
      if ($type) {
2473
         $parts = explode('/', $mime, 2);
2474
         return ($parts[0] == $type);
2475
      }
2476
      return ($mime);
2477
   }
2439 2478
}
2440 2479
?>
inc/user.class.php (copie de travail)
670 670
               }
671 671

  
672 672
            } else {
673
               $mime = mime_content_type($_FILES['picture']['tmp_name']);
674
               if (strstr($mime,'image')!==false) {
673
               if (toolbox::getMime($_FILES['picture']['tmp_name'], 'image')) {
675 674

  
676 675
                  // Unlink old picture (clean on changing format)
677 676
                  self::dropPictureFiles($this->fields['picture']);