[ PHPXref.com ] [ Generated: Sun Jul 20 19:56:57 2008 ] [ phpThumb() 1.7.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> phpThumb.php (source)

   1  <?php
   2  //////////////////////////////////////////////////////////////
   3  ///  phpThumb() by James Heinrich <info@silisoftware.com>   //
   4  //        available at http://phpthumb.sourceforge.net     ///
   5  //////////////////////////////////////////////////////////////
   6  ///                                                         //
   7  // See: phpthumb.changelog.txt for recent changes           //
   8  // See: phpthumb.readme.txt for usage instructions          //
   9  //                                                         ///
  10  //////////////////////////////////////////////////////////////
  11  
  12  error_reporting(E_ALL);
  13  ini_set('display_errors', '1');
  14  if (!@ini_get('safe_mode')) {
  15      set_time_limit(60);  // shouldn't take nearly this long in most cases, but with many filter and/or a slow server...
  16  }
  17  ini_set('magic_quotes_runtime', '0');
  18  if (@ini_get('magic_quotes_runtime')) {
  19      die('"magic_quotes_runtime" is set in php.ini, cannot run phpThumb with this enabled');
  20  }
  21  $starttime = array_sum(explode(' ', microtime()));
  22  
  23  // this script relies on the superglobal arrays, fake it here for old PHP versions
  24  if (phpversion() < '4.1.0') {
  25      $_SERVER = $HTTP_SERVER_VARS;
  26      $_GET    = $HTTP_GET_VARS;
  27  }
  28  
  29  // instantiate a new phpThumb() object
  30  ob_start();
  31  if (!include_once(dirname(__FILE__).'/phpthumb.class.php')) {
  32      ob_end_flush();
  33      die('failed to include_once("'.realpath(dirname(__FILE__).'/phpthumb.class.php').'")');
  34  }
  35  ob_end_clean();
  36  $phpThumb = new phpThumb();
  37  $phpThumb->DebugTimingMessage('phpThumb.php start', __FILE__, __LINE__, $starttime);
  38  
  39  // phpThumbDebug[0] used to be here, but may reveal too much
  40  // info when high_security_mode should be enabled (not set yet)
  41  
  42  if (file_exists(dirname(__FILE__).'/phpThumb.config.php')) {
  43      ob_start();
  44      if (include_once(dirname(__FILE__).'/phpThumb.config.php')) {
  45          // great
  46      } else {
  47          ob_end_flush();
  48          $phpThumb->ErrorImage('failed to include_once('.dirname(__FILE__).'/phpThumb.config.php) - realpath="'.realpath(dirname(__FILE__).'/phpThumb.config.php').'"');
  49      }
  50      ob_end_clean();
  51  } elseif (file_exists(dirname(__FILE__).'/phpThumb.config.php.default')) {
  52      $phpThumb->ErrorImage('Please rename "phpThumb.config.php.default" to "phpThumb.config.php"');
  53  } else {
  54      $phpThumb->ErrorImage('failed to include_once('.dirname(__FILE__).'/phpThumb.config.php) - realpath="'.realpath(dirname(__FILE__).'/phpThumb.config.php').'"');
  55  }
  56  
  57  if (!@$PHPTHUMB_CONFIG['disable_pathinfo_parsing'] && empty($_GET) && !empty($_SERVER['PATH_INFO'])) {
  58      $_SERVER['PHP_SELF'] = str_replace($_SERVER['PATH_INFO'], '', @$_SERVER['PHP_SELF']);
  59  
  60      $args = explode(';', substr($_SERVER['PATH_INFO'], 1));
  61      if (!empty($args)) {
  62          $_GET['src'] = @$args[count($args) - 1];
  63      }
  64      if (eregi('^([0-9]*)x?([0-9]*)$', @$args[count($args) - 2], $matches)) {
  65          $_GET['w'] = $matches[1];
  66          $_GET['h'] = $matches[2];
  67      }
  68      for ($i = 0; $i < count($args) - 2; $i++) {
  69          @list($key, $value) = explode('=', @$args[$i]);
  70          if (substr($key, -2) == '[]') {
  71              $_GET[substr($key, 0, -2)][] = $value;
  72          } else {
  73              $_GET[$key] = $value;
  74          }
  75      }
  76  }
  77  
  78  if (@$PHPTHUMB_CONFIG['high_security_enabled']) {
  79      if (!@$_GET['hash']) {
  80          $phpThumb->ErrorImage('ERROR: missing hash');
  81      } elseif (strlen($PHPTHUMB_CONFIG['high_security_password']) < 5) {
  82          $phpThumb->ErrorImage('ERROR: strlen($PHPTHUMB_CONFIG[high_security_password]) < 5');
  83      } elseif ($_GET['hash'] != md5(str_replace('&hash='.$_GET['hash'], '', $_SERVER['QUERY_STRING']).$PHPTHUMB_CONFIG['high_security_password'])) {
  84          $phpThumb->ErrorImage('ERROR: invalid hash');
  85      }
  86  }
  87  
  88  ////////////////////////////////////////////////////////////////
  89  // Debug output, to try and help me diagnose problems
  90  $phpThumb->DebugTimingMessage('phpThumbDebug[0]', __FILE__, __LINE__);
  91  if (@$_GET['phpThumbDebug'] == '0') {
  92      $phpThumb->phpThumbDebug();
  93  }
  94  ////////////////////////////////////////////////////////////////
  95  
  96  // returned the fixed string if the evil "magic_quotes_gpc" setting is on
  97  if (get_magic_quotes_gpc()) {
  98      $RequestVarsToStripSlashes = array('src', 'wmf', 'file', 'err', 'goto', 'down');
  99      foreach ($RequestVarsToStripSlashes as $dummy => $key) {
 100          if (isset($_GET[$key])) {
 101              $_GET[$key] = stripslashes($_GET[$key]);
 102          }
 103      }
 104  }
 105  
 106  if (!@$_SERVER['PATH_INFO'] && !@$_SERVER['QUERY_STRING']) {
 107  
 108      echo 'phpThumb() v'.$phpThumb->phpthumb_version.'<br><a href="http://phpthumb.sourceforge.net">http://phpthumb.sourceforge.net</a><br><br>ERROR: no parameters specified';
 109      unset($phpThumb);
 110      exit;
 111  
 112  }
 113  
 114  if (@$_GET['src'] && isset($_GET['md5s']) && empty($_GET['md5s'])) {
 115      if (eregi('^(f|ht)tps?://', $_GET['src'])) {
 116          if ($rawImageData = phpthumb_functions::SafeURLread($_GET['src'], $error)) {
 117              $md5s = md5($rawImageData);
 118          }
 119      } else {
 120          $SourceFilename = $phpThumb->ResolveFilenameToAbsolute($_GET['src']);
 121          if (is_readable($SourceFilename)) {
 122              $md5s = phpthumb_functions::md5_file_safe($SourceFilename);
 123          } else {
 124              $phpThumb->ErrorImage('ERROR: "'.$SourceFilename.'" cannot be read');
 125          }
 126      }
 127      if (@$_SERVER['HTTP_REFERER']) {
 128          $phpThumb->ErrorImage('&md5s='.$md5s);
 129      } else {
 130          die('&md5s='.$md5s);
 131      }
 132  }
 133  
 134  if (!empty($PHPTHUMB_CONFIG)) {
 135      foreach ($PHPTHUMB_CONFIG as $key => $value) {
 136          $keyname = 'config_'.$key;
 137          $phpThumb->setParameter($keyname, $value);
 138          if (!eregi('password', $key)) {
 139              $phpThumb->DebugMessage('setParameter('.$keyname.', '.$phpThumb->phpThumbDebugVarDump($value).')', __FILE__, __LINE__);
 140          }
 141      }
 142  } else {
 143      $phpThumb->DebugMessage('$PHPTHUMB_CONFIG is empty', __FILE__, __LINE__);
 144  }
 145  
 146  ////////////////////////////////////////////////////////////////
 147  // Debug output, to try and help me diagnose problems
 148  $phpThumb->DebugTimingMessage('phpThumbDebug[1]', __FILE__, __LINE__);
 149  if (@$_GET['phpThumbDebug'] == '1') {
 150      $phpThumb->phpThumbDebug();
 151  }
 152  ////////////////////////////////////////////////////////////////
 153  
 154  $parsed_url_referer = parse_url(@$_SERVER['HTTP_REFERER']);
 155  if ($phpThumb->config_nooffsitelink_require_refer && !in_array(@$parsed_url_referer['host'], $phpThumb->config_nohotlink_valid_domains)) {
 156      $phpThumb->ErrorImage('config_nooffsitelink_require_refer enabled and '.(@$parsed_url_referer['host'] ? '"'.$parsed_url_referer['host'].'" is not an allowed referer' : 'no HTTP_REFERER exists'));
 157  }
 158  $parsed_url_src = parse_url(@$_GET['src']);
 159  if ($phpThumb->config_nohotlink_enabled && $phpThumb->config_nohotlink_erase_image && eregi('^(f|ht)tps?://', @$_GET['src']) && !in_array(@$parsed_url_src['host'], $phpThumb->config_nohotlink_valid_domains)) {
 160      $phpThumb->ErrorImage($phpThumb->config_nohotlink_text_message);
 161  }
 162  
 163  if ($phpThumb->config_mysql_query) {
 164      if ($cid = @mysql_connect($phpThumb->config_mysql_hostname, $phpThumb->config_mysql_username, $phpThumb->config_mysql_password)) {
 165          if (@mysql_select_db($phpThumb->config_mysql_database, $cid)) {
 166              if ($result = @mysql_query($phpThumb->config_mysql_query, $cid)) {
 167                  if ($row = @mysql_fetch_array($result)) {
 168  
 169                      mysql_free_result($result);
 170                      mysql_close($cid);
 171                      $phpThumb->setSourceData($row[0]);
 172                      unset($row);
 173  
 174                  } else {
 175                      mysql_free_result($result);
 176                      mysql_close($cid);
 177                      $phpThumb->ErrorImage('no matching data in database.');
 178                  }
 179              } else {
 180                  mysql_close($cid);
 181                  $phpThumb->ErrorImage('Error in MySQL query: "'.mysql_error($cid).'"');
 182              }
 183          } else {
 184              mysql_close($cid);
 185              $phpThumb->ErrorImage('cannot select MySQL database: "'.mysql_error($cid).'"');
 186          }
 187      } else {
 188          $phpThumb->ErrorImage('cannot connect to MySQL server');
 189      }
 190      unset($_GET['id']);
 191  }
 192  
 193  ////////////////////////////////////////////////////////////////
 194  // Debug output, to try and help me diagnose problems
 195  $phpThumb->DebugTimingMessage('phpThumbDebug[2]', __FILE__, __LINE__);
 196  if (@$_GET['phpThumbDebug'] == '2') {
 197      $phpThumb->phpThumbDebug();
 198  }
 199  ////////////////////////////////////////////////////////////////
 200  
 201  if (@$PHPTHUMB_CONFIG['cache_default_only_suffix'] && (strpos($PHPTHUMB_CONFIG['cache_default_only_suffix'], '*') !== false)) {
 202      $PHPTHUMB_DEFAULTS_DISABLEGETPARAMS = true;
 203  }
 204  $allowedGETparameters = array('src', 'new', 'w', 'h', 'wp', 'hp', 'wl', 'hl', 'ws', 'hs', 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'zc', 'bc', 'bg', 'bgt', 'fltr', 'file', 'goto', 'err', 'xto', 'ra', 'ar', 'aoe', 'far', 'iar', 'maxb', 'down', 'phpThumbDebug', 'hash', 'md5s');
 205  foreach ($_GET as $key => $value) {
 206      if (@$PHPTHUMB_DEFAULTS_DISABLEGETPARAMS && ($key != 'src')) {
 207          // disabled, do not set parameter
 208          $phpThumb->DebugMessage('ignoring $_GET['.$key.'] because of $PHPTHUMB_DEFAULTS_DISABLEGETPARAMS', __FILE__, __LINE__);
 209      } elseif (in_array($key, $allowedGETparameters)) {
 210          $phpThumb->DebugMessage('setParameter('.$key.', '.$phpThumb->phpThumbDebugVarDump($value).')', __FILE__, __LINE__);
 211          $phpThumb->setParameter($key, $value);
 212      } else {
 213          $phpThumb->ErrorImage('Forbidden parameter: '.$key);
 214      }
 215  }
 216  
 217  if (!empty($PHPTHUMB_DEFAULTS) && is_array($PHPTHUMB_DEFAULTS)) {
 218      $phpThumb->DebugMessage('setting $PHPTHUMB_DEFAULTS['.implode(';', array_keys($PHPTHUMB_DEFAULTS)).']', __FILE__, __LINE__);
 219      foreach ($PHPTHUMB_DEFAULTS as $key => $value) {
 220          if ($PHPTHUMB_DEFAULTS_GETSTRINGOVERRIDE || !isset($_GET[$key])) {
 221              $phpThumb->DebugMessage('setParameter('.$key.', '.$phpThumb->phpThumbDebugVarDump($value).')', __FILE__, __LINE__);
 222              $phpThumb->setParameter($key, $value);
 223          }
 224      }
 225  }
 226  
 227  ////////////////////////////////////////////////////////////////
 228  // Debug output, to try and help me diagnose problems
 229  $phpThumb->DebugTimingMessage('phpThumbDebug[3]', __FILE__, __LINE__);
 230  if (@$_GET['phpThumbDebug'] == '3') {
 231      $phpThumb->phpThumbDebug();
 232  }
 233  ////////////////////////////////////////////////////////////////
 234  
 235  //if (!@$_GET['phpThumbDebug'] && !$phpThumb->sourceFilename && !function_exists('ImageJPEG') && !function_exists('ImagePNG') && !function_exists('ImageGIF')) {
 236  if (!@$_GET['phpThumbDebug'] && !is_file($phpThumb->sourceFilename) && !phpthumb_functions::gd_version()) {
 237      if (!headers_sent()) {
 238          // base64-encoded error image in GIF format
 239          $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
 240          header('Content-Type: image/gif');
 241          echo base64_decode($ERROR_NOGD);
 242      } else {
 243          echo '*** ERROR: No PHP-GD support available ***';
 244      }
 245      exit;
 246  }
 247  
 248  // check to see if file can be output from source with no processing or caching
 249  $CanPassThroughDirectly = true;
 250  if ($phpThumb->rawImageData) {
 251      // data from SQL, should be fine
 252  } elseif (eregi('^(f|ht)tp\://', $phpThumb->src)) {
 253      $phpThumb->DebugMessage('$CanPassThroughDirectly=false because eregi("^(f|ht)tp\://", '.$phpThumb->src.')', __FILE__, __LINE__);
 254      $CanPassThroughDirectly = false;
 255  } elseif (!@is_file($phpThumb->sourceFilename)) {
 256      $phpThumb->DebugMessage('$CanPassThroughDirectly=false because !@is_file('.$phpThumb->sourceFilename.')', __FILE__, __LINE__);
 257      $CanPassThroughDirectly = false;
 258  } elseif (!@is_readable($phpThumb->sourceFilename)) {
 259      $phpThumb->DebugMessage('$CanPassThroughDirectly=false because !@is_readable('.$phpThumb->sourceFilename.')', __FILE__, __LINE__);
 260      $CanPassThroughDirectly = false;
 261  }
 262  foreach ($_GET as $key => $value) {
 263      switch ($key) {
 264          case 'src':
 265              // allowed
 266              break;
 267  
 268          case 'w':
 269          case 'h':
 270              // might be OK if exactly matches original
 271              break;
 272  
 273          case 'phpThumbDebug':
 274              // handled in direct-passthru code
 275              break;
 276  
 277          default:
 278              // all other parameters will cause some processing,
 279              // therefore cannot pass through original image unmodified
 280              $CanPassThroughDirectly = false;
 281              $UnAllowedGET[] = $key;
 282              break;
 283      }
 284  }
 285  if (!empty($UnAllowedGET)) {
 286      $phpThumb->DebugMessage('$CanPassThroughDirectly=false because $_GET['.implode(';', array_unique($UnAllowedGET)).'] are set', __FILE__, __LINE__);
 287  }
 288  
 289  ////////////////////////////////////////////////////////////////
 290  // Debug output, to try and help me diagnose problems
 291  $phpThumb->DebugTimingMessage('phpThumbDebug[4]', __FILE__, __LINE__);
 292  if (@$_GET['phpThumbDebug'] == '4') {
 293      $phpThumb->phpThumbDebug();
 294  }
 295  ////////////////////////////////////////////////////////////////
 296  
 297  function SendSaveAsFileHeaderIfNeeded() {
 298      if (headers_sent()) {
 299          return false;
 300      }
 301      global $phpThumb;
 302      if (@$_GET['down']) {
 303          $downloadfilename = ereg_replace('[/\\:\*\?"<>|]', '_', $_GET['down']);
 304          if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
 305              $downloadfilename = trim($downloadfilename, '.');
 306          }
 307          if (@$downloadfilename) {
 308              $phpThumb->DebugMessage('SendSaveAsFileHeaderIfNeeded() sending header: Content-Disposition: attachment; filename="'.$downloadfilename.'"', __FILE__, __LINE__);
 309              header('Content-Disposition: attachment; filename="'.$downloadfilename.'"');
 310              return true;
 311          }
 312      }
 313      $phpThumb->DebugMessage('SendSaveAsFileHeaderIfNeeded() sending header: Content-Disposition: inline', __FILE__, __LINE__);
 314      header('Content-Disposition: inline');
 315      return true;
 316  }
 317  
 318  $phpThumb->DebugMessage('$CanPassThroughDirectly="'.intval($CanPassThroughDirectly).'" && $phpThumb->src="'.$phpThumb->src.'"', __FILE__, __LINE__);
 319  while ($CanPassThroughDirectly && $phpThumb->src) {
 320      // no parameters set, passthru
 321      $SourceFilename = $phpThumb->ResolveFilenameToAbsolute($phpThumb->src);
 322  
 323      // security and size checks
 324      if ($phpThumb->getimagesizeinfo = @GetImageSize($SourceFilename)) {
 325          $phpThumb->DebugMessage('Direct passthru GetImageSize() returned [w='.$phpThumb->getimagesizeinfo[0].';h='.$phpThumb->getimagesizeinfo[1].';t='.$phpThumb->getimagesizeinfo[2].']', __FILE__, __LINE__);
 326  
 327          if (!@$_REQUEST['w'] && !@$_REQUEST['wp'] && !@$_REQUEST['wl'] && !@$_REQUEST['ws'] && !@$_REQUEST['h'] && !@$_REQUEST['hp'] && !@$_REQUEST['hl'] && !@$_REQUEST['hs']) {
 328              // no resizing needed
 329              $phpThumb->DebugMessage('Passing "'.$SourceFilename.'" through directly, no resizing required ("'.$phpThumb->getimagesizeinfo[0].'"x"'.$phpThumb->getimagesizeinfo[1].'")', __FILE__, __LINE__);
 330          } elseif (($phpThumb->getimagesizeinfo[0] <= @$_REQUEST['w']) && ($phpThumb->getimagesizeinfo[1] <= @$_REQUEST['h']) && ((@$_REQUEST['w'] == $phpThumb->getimagesizeinfo[0]) || (@$_REQUEST['h'] == $phpThumb->getimagesizeinfo[1]))) {
 331              // image fits into 'w'x'h' box, and at least one dimension matches exactly, therefore no resizing needed
 332              $phpThumb->DebugMessage('Passing "'.$SourceFilename.'" through directly, no resizing required ("'.$phpThumb->getimagesizeinfo[0].'"x"'.$phpThumb->getimagesizeinfo[1].'" fits inside "'.@$_REQUEST['w'].'"x"'.@$_REQUEST['h'].'")', __FILE__, __LINE__);
 333          } else {
 334              $phpThumb->DebugMessage('Not passing "'.$SourceFilename.'" through directly because resizing required (from "'.$phpThumb->getimagesizeinfo[0].'"x"'.$phpThumb->getimagesizeinfo[1].'" to "'.@$_REQUEST['w'].'"x"'.@$_REQUEST['h'].'")', __FILE__, __LINE__);
 335              break;
 336          }
 337          switch ($phpThumb->getimagesizeinfo[2]) {
 338              case 1: // GIF
 339              case 2: // JPG
 340              case 3: // PNG
 341                  // great, let it through
 342                  break;
 343              default:
 344                  // browser probably can't handle format, remangle it to JPEG/PNG/GIF
 345                  $phpThumb->DebugMessage('Not passing "'.$SourceFilename.'" through directly because $phpThumb->getimagesizeinfo[2] = "'.$phpThumb->getimagesizeinfo[2].'"', __FILE__, __LINE__);
 346                  break 2;
 347          }
 348  
 349          $ImageCreateFunctions = array(1=>'ImageCreateFromGIF', 2=>'ImageCreateFromJPEG', 3=>'ImageCreateFromPNG');
 350          $theImageCreateFunction = @$ImageCreateFunctions[$phpThumb->getimagesizeinfo[2]];
 351          if ($phpThumb->config_disable_onlycreateable_passthru || (function_exists($theImageCreateFunction) && ($dummyImage = @$theImageCreateFunction($SourceFilename)))) {
 352  
 353              // great
 354              if (@is_resource($dummyImage)) {
 355                  unset($dummyImage);
 356              }
 357  
 358              if (headers_sent()) {
 359                  $phpThumb->ErrorImage('Headers already sent ('.basename(__FILE__).' line '.__LINE__.')');
 360                  exit;
 361              }
 362              if (@$_GET['phpThumbDebug']) {
 363                  $phpThumb->DebugTimingMessage('skipped direct $SourceFilename passthru', __FILE__, __LINE__);
 364                  $phpThumb->DebugMessage('Would have passed "'.$SourceFilename.'" through directly, but skipping due to phpThumbDebug', __FILE__, __LINE__);
 365                  break;
 366              }
 367  
 368              SendSaveAsFileHeaderIfNeeded();
 369              header('Last-Modified: '.gmdate('D, d M Y H:i:s', @filemtime($SourceFilename)).' GMT');
 370              if ($contentType = phpthumb_functions::ImageTypeToMIMEtype(@$phpThumb->getimagesizeinfo[2])) {
 371                  header('Content-Type: '.$contentType);
 372              }
 373              @readfile($SourceFilename);
 374              exit;
 375  
 376          } else {
 377              $phpThumb->DebugMessage('Not passing "'.$SourceFilename.'" through directly because ($phpThumb->config_disable_onlycreateable_passthru = "'.$phpThumb->config_disable_onlycreateable_passthru.'") and '.$theImageCreateFunction.'() failed', __FILE__, __LINE__);
 378              break;
 379          }
 380  
 381      } else {
 382          $phpThumb->DebugMessage('Not passing "'.$SourceFilename.'" through directly because GetImageSize() failed', __FILE__, __LINE__);
 383          break;
 384      }
 385      break;
 386  }
 387  
 388  ////////////////////////////////////////////////////////////////
 389  // Debug output, to try and help me diagnose problems
 390  $phpThumb->DebugTimingMessage('phpThumbDebug[5]', __FILE__, __LINE__);
 391  if (@$_GET['phpThumbDebug'] == '5') {
 392      $phpThumb->phpThumbDebug();
 393  }
 394  ////////////////////////////////////////////////////////////////
 395  
 396  function RedirectToCachedFile() {
 397      global $phpThumb, $PHPTHUMB_CONFIG;
 398  
 399      $nice_cachefile = str_replace(DIRECTORY_SEPARATOR, '/', $phpThumb->cache_filename);
 400      $nice_docroot   = str_replace(DIRECTORY_SEPARATOR, '/', rtrim($PHPTHUMB_CONFIG['document_root'], '/\\'));
 401  
 402      $parsed_url = @parse_url(@$_SERVER['HTTP_REFERER']);
 403  
 404      $nModified  = filemtime($phpThumb->cache_filename);
 405  
 406      if ($phpThumb->config_nooffsitelink_enabled && @$_SERVER['HTTP_REFERER'] && !in_array(@$parsed_url['host'], $phpThumb->config_nooffsitelink_valid_domains)) {
 407  
 408          $phpThumb->DebugMessage('Would have used cached (image/'.$phpThumb->thumbnailFormat.') file "'.$phpThumb->cache_filename.'" (Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT), but skipping because $_SERVER[HTTP_REFERER] ('.@$_SERVER['HTTP_REFERER'].') is not in $phpThumb->config_nooffsitelink_valid_domains ('.implode(';', $phpThumb->config_nooffsitelink_valid_domains).')', __FILE__, __LINE__);
 409  
 410      } elseif ($phpThumb->phpThumbDebug) {
 411  
 412          $phpThumb->DebugTimingMessage('skipped using cached image', __FILE__, __LINE__);
 413          $phpThumb->DebugMessage('Would have used cached file, but skipping due to phpThumbDebug', __FILE__, __LINE__);
 414          $phpThumb->DebugMessage('* Would have sent headers (1): Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT', __FILE__, __LINE__);
 415          if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) {
 416              $phpThumb->DebugMessage('* Would have sent headers (2): Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]), __FILE__, __LINE__);
 417          }
 418          if (ereg('^'.preg_quote($nice_docroot).'(.*)$', $nice_cachefile, $matches)) {
 419              $phpThumb->DebugMessage('* Would have sent headers (3): Location: '.dirname($matches[1]).'/'.urlencode(basename($matches[1])), __FILE__, __LINE__);
 420          } else {
 421              $phpThumb->DebugMessage('* Would have sent data: readfile('.$phpThumb->cache_filename.')', __FILE__, __LINE__);
 422          }
 423  
 424      } else {
 425  
 426          if (headers_sent()) {
 427              $phpThumb->ErrorImage('Headers already sent ('.basename(__FILE__).' line '.__LINE__.')');
 428              exit;
 429          }
 430          SendSaveAsFileHeaderIfNeeded();
 431  
 432          header('Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT');
 433          if (@$_SERVER['HTTP_IF_MODIFIED_SINCE'] && ($nModified == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) && @$_SERVER['SERVER_PROTOCOL']) {
 434              header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
 435              exit;
 436          }
 437  
 438          if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) {
 439              header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]));
 440          } elseif (eregi('\.ico$', $phpThumb->cache_filename)) {
 441              header('Content-Type: image/x-icon');
 442          }
 443          if (!@$PHPTHUMB_CONFIG['cache_force_passthru'] && ereg('^'.preg_quote($nice_docroot).'(.*)$', $nice_cachefile, $matches)) {
 444              header('Location: '.dirname($matches[1]).'/'.urlencode(basename($matches[1])));
 445          } else {
 446              @readfile($phpThumb->cache_filename);
 447          }
 448          exit;
 449  
 450      }
 451      return true;
 452  }
 453  
 454  // check to see if file already exists in cache, and output it with no processing if it does
 455  $phpThumb->SetCacheFilename();
 456  if (@is_file($phpThumb->cache_filename)) {
 457      RedirectToCachedFile();
 458  } else {
 459      $phpThumb->DebugMessage('Cached file "'.$phpThumb->cache_filename.'" does not exist, processing as normal', __FILE__, __LINE__);
 460  }
 461  
 462  ////////////////////////////////////////////////////////////////
 463  // Debug output, to try and help me diagnose problems
 464  $phpThumb->DebugTimingMessage('phpThumbDebug[6]', __FILE__, __LINE__);
 465  if (@$_GET['phpThumbDebug'] == '6') {
 466      $phpThumb->phpThumbDebug();
 467  }
 468  ////////////////////////////////////////////////////////////////
 469  
 470  if ($phpThumb->rawImageData) {
 471  
 472      // great
 473  
 474  } elseif (@$_GET['new']) {
 475  
 476      // generate a blank image resource of the specified size/background color/opacity
 477      if (($phpThumb->w <= 0) || ($phpThumb->h <= 0)) {
 478          $phpThumb->ErrorImage('"w" and "h" parameters required for "new"');
 479      }
 480      @list($bghexcolor, $opacity) = explode('|', $_GET['new']);
 481      if (!phpthumb_functions::IsHexColor($bghexcolor)) {
 482          $phpThumb->ErrorImage('BGcolor parameter for "new" is not valid');
 483      }
 484      $opacity = (strlen($opacity) ? $opacity : 100);
 485      if ($phpThumb->gdimg_source = phpthumb_functions::ImageCreateFunction($phpThumb->w, $phpThumb->h)) {
 486          $alpha = (100 - min(100, max(0, $opacity))) * 1.27;
 487          if ($alpha) {
 488              $phpThumb->setParameter('is_alpha', true);
 489              ImageAlphaBlending($phpThumb->gdimg_source, false);
 490              phpthumb_functions::gd_ImageSaveAlpha($phpThumb->gdimg_source, true);
 491          }
 492          $new_background_color = phpthumb_functions::ImageHexColorAllocate($phpThumb->gdimg_source, $bghexcolor, false, $alpha);
 493          ImageFilledRectangle($phpThumb->gdimg_source, 0, 0, $phpThumb->w, $phpThumb->h, $new_background_color);
 494      } else {
 495          $phpThumb->ErrorImage('failed to create "new" image ('.$phpThumb->w.'x'.$phpThumb->h.')');
 496      }
 497  
 498  } elseif (!$phpThumb->src) {
 499  
 500      $phpThumb->ErrorImage('Usage: '.$_SERVER['PHP_SELF'].'?src=/path/and/filename.jpg'."\n".'read Usage comments for details');
 501  
 502  } elseif (eregi('^(f|ht)tp\://', $phpThumb->src)) {
 503  
 504      if ($phpThumb->config_http_user_agent) {
 505          ini_set('user_agent', $phpThumb->config_http_user_agent);
 506      }
 507      $basename = preg_quote(basename($phpThumb->src));
 508      $encoded  = rawurlencode(basename($phpThumb->src));
 509      $HTTPurl = ereg_replace('(.*)'.$basename.'$', '\\1'.$encoded, $phpThumb->src);
 510      if ($rawImageData = phpthumb_functions::SafeURLread($HTTPurl, $error)) {
 511          $phpThumb->setSourceData($rawImageData, urlencode($phpThumb->src));
 512      } else {
 513          $phpThumb->ErrorImage($error);
 514      }
 515  
 516  }
 517  
 518  ////////////////////////////////////////////////////////////////
 519  // Debug output, to try and help me diagnose problems
 520  $phpThumb->DebugTimingMessage('phpThumbDebug[7]', __FILE__, __LINE__);
 521  if (@$_GET['phpThumbDebug'] == '7') {
 522      $phpThumb->phpThumbDebug();
 523  }
 524  ////////////////////////////////////////////////////////////////
 525  
 526  $phpThumb->GenerateThumbnail();
 527  
 528  ////////////////////////////////////////////////////////////////
 529  // Debug output, to try and help me diagnose problems
 530  $phpThumb->DebugTimingMessage('phpThumbDebug[8]', __FILE__, __LINE__);
 531  if (@$_GET['phpThumbDebug'] == '8') {
 532      $phpThumb->phpThumbDebug();
 533  }
 534  ////////////////////////////////////////////////////////////////
 535  
 536  if ($phpThumb->config_allow_parameter_file && $phpThumb->file) {
 537  
 538      $phpThumb->RenderToFile($phpThumb->ResolveFilenameToAbsolute($phpThumb->file));
 539      if ($phpThumb->config_allow_parameter_goto && $phpThumb->goto && eregi('^(f|ht)tps?://', $phpThumb->goto)) {
 540          // redirect to another URL after image has been rendered to file
 541          header('Location: '.$phpThumb->goto);
 542          exit;
 543      }
 544  
 545  } else {
 546  
 547      if ((file_exists($phpThumb->cache_filename) && is_writable($phpThumb->cache_filename)) || is_writable(dirname($phpThumb->cache_filename))) {
 548  
 549          $phpThumb->CleanUpCacheDirectory();
 550          if ($phpThumb->RenderToFile($phpThumb->cache_filename) && is_readable($phpThumb->cache_filename)) {
 551              chmod($phpThumb->cache_filename, 0644);
 552              RedirectToCachedFile();
 553          } else {
 554              $phpThumb->DebugMessage('Failed: RenderToFile('.$phpThumb->cache_filename.')', __FILE__, __LINE__);
 555          }
 556  
 557      } else {
 558  
 559          $phpThumb->DebugMessage('Cannot write to $phpThumb->cache_filename ('.$phpThumb->cache_filename.') because that directory ('.dirname($phpThumb->cache_filename).') is not writable', __FILE__, __LINE__);
 560  
 561      }
 562  
 563  }
 564  
 565  ////////////////////////////////////////////////////////////////
 566  // Debug output, to try and help me diagnose problems
 567  $phpThumb->DebugTimingMessage('phpThumbDebug[9]', __FILE__, __LINE__);
 568  if (@$_GET['phpThumbDebug'] == '9') {
 569      $phpThumb->phpThumbDebug();
 570  }
 571  ////////////////////////////////////////////////////////////////
 572  
 573  if (!$phpThumb->OutputThumbnail()) {
 574      $phpThumb->ErrorImage('Error in OutputThumbnail():'."\n".$phpThumb->debugmessages[(count($phpThumb->debugmessages) - 1)]);
 575  }
 576  
 577  ////////////////////////////////////////////////////////////////
 578  // Debug output, to try and help me diagnose problems
 579  $phpThumb->DebugTimingMessage('phpThumbDebug[10]', __FILE__, __LINE__);
 580  if (@$_GET['phpThumbDebug'] == '10') {
 581      $phpThumb->phpThumbDebug();
 582  }
 583  ////////////////////////////////////////////////////////////////
 584  
 585  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]