khashnan / timthumb

Automatically exported from code.google.com/p/timthumb
0 stars 0 forks source link

Self-made improvements #194

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
To avoid the following notices I made some extra checks in the PHP code. This 
could be handy to add to newer versions.

PHP Notice:  getimagesize(): Read error! in /path/to/timthumb.php on line 451
PHP Notice:  Undefined index: extension in /path/to/timthumb.php on line 599

So I modified the:
function mime_type ($file) {

  if (array_key_exists('mime', (getimagesize($file)))) {
      $file_infos = getimagesize($file);
      $mime_type = $file_infos['mime'];

      // no mime type
      if (empty($mime_type)) {
          display_error('no mime type specified');
      }

      // use mime_type to determine mime type
      if (!preg_match("/jpg|jpeg|gif|png/i", $mime_type)) {
          display_error('Invalid src mime type: ' . $mime_type);
      }

      $mime_type = strtolower($mime_type);
      $mime_type = str_replace('image/', '', $mime_type);

      if ($mime_type == 'jpeg') {
          $mime_type = 'jpg';
      }

      return $mime_type;
  } else {
      display_error('can\'t read mime type');
      return "";
  }
}

And replaced line 599 by:
    $local_filepath = DIRECTORY_CACHE . '/' . $filename . '.';
    if (isset($extension))
    {$local_filepath .= strtolower ($extension);}

Original issue reported on code.google.com by m...@maartenklok.nl on 31 May 2011 at 12:16

GoogleCodeExporter commented 8 years ago
Thanks for the pointers. That's brought up a couple of bugs that definitely 
need looking at. Will sort them out.

Original comment by BinaryMoon on 9 Jun 2011 at 2:33

GoogleCodeExporter commented 8 years ago

Original comment by BinaryMoon on 10 Jun 2011 at 6:26

GoogleCodeExporter commented 8 years ago
Thank you very much for the help!

Original comment by i...@veteranlink.hu on 16 Oct 2011 at 7:04