示例#1
0
        }
        exit;
    }
    return true;
}
// instantiate a new phpThumb() object
ob_start();
if (!(include_once dirname(__FILE__) . '/phpThumb.class.php')) {
    ob_end_flush();
    die('failed to include_once("' . realpath(dirname(__FILE__) . '/phpThumb.class.php') . '")');
}
ob_end_clean();
$phpThumb = new phpThumb();
$phpThumb->DebugTimingMessage('phpThumb.php start', __FILE__, __LINE__, $starttime);
$phpThumb->SetParameter('config_error_die_on_error', true);
if (!phpThumb_functions::FunctionIsDisabled('set_time_limit')) {
    set_time_limit(60);
    // shouldn't take nearly this long in most cases, but with many filters and/or a slow server...
}
// phpThumbDebug[0] used to be here, but may reveal too much
// info when high_security_mode should be enabled (not set yet)
if (file_exists(dirname(__FILE__) . '/phpThumb.config.php')) {
    ob_start();
    if (include_once dirname(__FILE__) . '/phpThumb.config.php') {
        // great
    } else {
        ob_end_flush();
        $phpThumb->config_disable_debug = false;
        // otherwise error message won't print
        $phpThumb->ErrorImage('failed to include_once(' . dirname(__FILE__) . '/phpThumb.config.php) - realpath="' . realpath(dirname(__FILE__) . '/phpThumb.config.php') . '"');
    }
 function PlotBMP(&$BMPinfo)
 {
     $starttime = time();
     if (!isset($BMPinfo['bmp']['data']) || !is_array($BMPinfo['bmp']['data'])) {
         echo 'ERROR: no pixel data<BR>';
         return false;
     }
     if (!phpThumb_functions::FunctionIsDisabled('set_time_limit')) {
         set_time_limit(intval(round($BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] / 10000)));
     }
     $im = $this->PlotPixelsGD($BMPinfo['bmp']);
     if (headers_sent()) {
         echo 'plotted ' . $BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] . ' pixels in ' . (time() - $starttime) . ' seconds<BR>';
         ImageDestroy($im);
         exit;
     } else {
         header('Content-Type: image/png');
         ImagePNG($im);
         ImageDestroy($im);
         return true;
     }
     return false;
 }
 static function SafeURLread($url, &$error, $timeout = 10, $followredirects = true)
 {
     $error = '';
     $parsed_url = phpThumb_functions::ParseURLbetter($url);
     $alreadyLookedAtURLs[trim($url)] = true;
     while (true) {
         $tryagain = false;
         $rawData = phpThumb_functions::URLreadFsock(@$parsed_url['host'], @$parsed_url['path'] . '?' . @$parsed_url['query'], $errstr, true, @$parsed_url['port'] ? @$parsed_url['port'] : 80, $timeout);
         if (preg_match('#302 [a-z ]+; Location\\: (http.*)#i', $errstr, $matches)) {
             $matches[1] = trim(@$matches[1]);
             if (!@$alreadyLookedAtURLs[$matches[1]]) {
                 // loop through and examine new URL
                 $error .= 'URL "' . $url . '" redirected to "' . $matches[1] . '"';
                 $tryagain = true;
                 $alreadyLookedAtURLs[$matches[1]] = true;
                 $parsed_url = phpThumb_functions::ParseURLbetter($matches[1]);
             }
         }
         if (!$tryagain) {
             break;
         }
     }
     if ($rawData === false) {
         $error .= 'Error opening "' . $url . '":' . "\n\n" . $errstr;
         return false;
     } elseif ($rawData === null) {
         // fall through
         $error .= 'Error opening "' . $url . '":' . "\n\n" . $errstr;
     } else {
         return $rawData;
     }
     if (function_exists('curl_version') && !phpThumb_functions::FunctionIsDisabled('curl_exec')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
         $rawData = curl_exec($ch);
         curl_close($ch);
         if (strlen($rawData) > 0) {
             $error .= 'CURL succeeded (' . strlen($rawData) . ' bytes); ';
             return $rawData;
         }
         $error .= 'CURL available but returned no data; ';
     } else {
         $error .= 'CURL unavailable; ';
     }
     $BrokenURLfopenPHPversions = array('4.4.2');
     if (in_array(phpversion(), $BrokenURLfopenPHPversions)) {
         $error .= 'fopen(URL) broken in PHP v' . phpversion() . '; ';
     } elseif (@ini_get('allow_url_fopen')) {
         $rawData = '';
         $error_fopen = '';
         ob_start();
         if ($fp = fopen($url, 'rb')) {
             do {
                 $buffer = fread($fp, 8192);
                 $rawData .= $buffer;
             } while (strlen($buffer) > 0);
             fclose($fp);
         } else {
             $error_fopen .= trim(strip_tags(ob_get_contents()));
         }
         ob_end_clean();
         $error .= $error_fopen;
         if (!$error_fopen) {
             $error .= '; "allow_url_fopen" succeeded (' . strlen($rawData) . ' bytes); ';
             return $rawData;
         }
         $error .= '; "allow_url_fopen" enabled but returned no data (' . $error_fopen . '); ';
     } else {
         $error .= '"allow_url_fopen" disabled; ';
     }
     return false;
 }