📄 phpthumb.php
字号:
global $phpThumb;
if (@$_GET['down']) {
$downloadfilename = ereg_replace('[/\\:\*\?"<>|]', '_', $_GET['down']);
if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
$downloadfilename = trim($downloadfilename, '.');
}
if (@$downloadfilename) {
$phpThumb->DebugMessage('SendSaveAsFileHeaderIfNeeded() sending header: Content-Disposition: attachment; filename="'.$downloadfilename.'"', __FILE__, __LINE__);
header('Content-Disposition: attachment; filename="'.$downloadfilename.'"');
return true;
}
}
$phpThumb->DebugMessage('SendSaveAsFileHeaderIfNeeded() sending header: Content-Disposition: inline', __FILE__, __LINE__);
header('Content-Disposition: inline');
return true;
}
while ($CanPassThroughDirectly && $phpThumb->src) {
// no parameters set, passthru
$SourceFilename = $phpThumb->ResolveFilenameToAbsolute($phpThumb->src);
if (@$_GET['phpThumbDebug']) {
$phpThumb->DebugMessage('Would have passed "'.$SourceFilename.'" through directly, but skipping due to phpThumbDebug', __FILE__, __LINE__);
} else {
// security checks
if ($GetImageSize = @GetImageSize($SourceFilename)) {
$ImageCreateFunctions = array(1=>'ImageCreateFromGIF', 2=>'ImageCreateFromJPEG', 3=>'ImageCreateFromPNG');
if (@$ImageCreateFunctions[$GetImageSize[2]]) {
$theFunction = $ImageCreateFunctions[$GetImageSize[2]];
if (function_exists($theFunction) && ($dummyImage = @$theFunction($SourceFilename))) {
// great
unset($dummyImage);
} else {
$phpThumb->DebugMessage('Not passing "'.$SourceFilename.'" through directly because '.$theFunction.'() failed', __FILE__, __LINE__);
break;
}
} else {
$phpThumb->DebugMessage('Not passing "'.$SourceFilename.'" through directly because GetImageSize() returned unhandled image type "'.$GetImageSize[2].'"', __FILE__, __LINE__);
break;
}
} else {
$phpThumb->DebugMessage('Not passing "'.$SourceFilename.'" through directly because GetImageSize() failed', __FILE__, __LINE__);
break;
}
if (headers_sent()) {
$phpThumb->ErrorImage('Headers already sent ('.basename(__FILE__).' line '.__LINE__.')');
exit;
}
SendSaveAsFileHeaderIfNeeded();
header('Last-Modified: '.gmdate('D, d M Y H:i:s', @filemtime($SourceFilename)).' GMT');
if (@$GetImageSize[2]) {
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($GetImageSize[2]));
}
@readfile($SourceFilename);
exit;
}
break;
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[5]', __FILE__, __LINE__);
if (@$_GET['phpThumbDebug'] == '5') {
$phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
function RedirectToCachedFile() {
global $phpThumb, $PHPTHUMB_CONFIG;
$nice_cachefile = str_replace($phpThumb->osslash, '/', $phpThumb->cache_filename);
$nice_docroot = str_replace($phpThumb->osslash, '/', rtrim($PHPTHUMB_CONFIG['document_root'], '/\\'));
$parsed_url = @parse_url(@$_SERVER['HTTP_REFERER']);
$nModified = filemtime($phpThumb->cache_filename);
if ($phpThumb->config_nooffsitelink_enabled && @$_SERVER['HTTP_REFERER'] && !in_array(@$parsed_url['host'], $phpThumb->config_nooffsitelink_valid_domains)) {
$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__);
} elseif ($phpThumb->phpThumbDebug) {
$phpThumb->DebugMessage('Would have used cached file, but skipping due to phpThumbDebug', __FILE__, __LINE__);
$phpThumb->DebugMessage('* Would have sent headers (1): Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT', __FILE__, __LINE__);
if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) {
$phpThumb->DebugMessage('* Would have sent headers (2): Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]), __FILE__, __LINE__);
}
if (ereg('^'.preg_quote($nice_docroot).'(.*)$', $nice_cachefile, $matches)) {
$phpThumb->DebugMessage('* Would have sent headers (3): Location: '.dirname($matches[1]).'/'.urlencode(basename($matches[1])), __FILE__, __LINE__);
} else {
$phpThumb->DebugMessage('* Would have sent data: readfile('.$phpThumb->cache_filename.')', __FILE__, __LINE__);
}
} else {
if (headers_sent()) {
$phpThumb->ErrorImage('Headers already sent ('.basename(__FILE__).' line '.__LINE__.')');
exit;
}
SendSaveAsFileHeaderIfNeeded();
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT');
if (@$_SERVER['HTTP_IF_MODIFIED_SINCE'] && ($nModified == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) && @$_SERVER['SERVER_PROTOCOL']) {
header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
exit;
}
if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) {
header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]));
}
if (ereg('^'.preg_quote($nice_docroot).'(.*)$', $nice_cachefile, $matches)) {
header('Location: '.dirname($matches[1]).'/'.urlencode(basename($matches[1])));
} else {
@readfile($phpThumb->cache_filename);
}
exit;
}
return true;
}
// check to see if file already exists in cache, and output it with no processing if it does
$phpThumb->SetCacheFilename();
if (is_file($phpThumb->cache_filename)) {
RedirectToCachedFile();
} else {
$phpThumb->DebugMessage('Cached file "'.$phpThumb->cache_filename.'" does not exist, processing as normal', __FILE__, __LINE__);
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[6]', __FILE__, __LINE__);
if (@$_GET['phpThumbDebug'] == '6') {
$phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
if ($phpThumb->rawImageData) {
// great
} elseif (@$_GET['new']) {
// generate a blank image resource of the specified size/background color/opacity
if (($phpThumb->w <= 0) || ($phpThumb->h <= 0)) {
$phpThumb->ErrorImage('"w" and "h" parameters required for "new"');
}
@list($bghexcolor, $opacity) = explode('|', $_GET['new']);
if (!phpthumb_functions::IsHexColor($bghexcolor)) {
$phpThumb->ErrorImage('BGcolor parameter for "new" is not valid');
}
$opacity = (strlen($opacity) ? $opacity : 100);
if ($phpThumb->gdimg_source = phpthumb_functions::ImageCreateFunction($phpThumb->w, $phpThumb->h)) {
$alpha = (100 - min(100, max(0, $opacity))) * 1.27;
if ($alpha) {
$phpThumb->setParameter('is_alpha', true);
ImageAlphaBlending($phpThumb->gdimg_source, false);
ImageSaveAlpha($phpThumb->gdimg_source, true);
}
$new_background_color = phpthumb_functions::ImageHexColorAllocate($phpThumb->gdimg_source, $bghexcolor, false, $alpha);
ImageFilledRectangle($phpThumb->gdimg_source, 0, 0, $phpThumb->w, $phpThumb->h, $new_background_color);
} else {
$phpThumb->ErrorImage('failed to create "new" image ('.$phpThumb->w.'x'.$phpThumb->h.')');
}
} elseif (!$phpThumb->src) {
$phpThumb->ErrorImage('Usage: '.$_SERVER['PHP_SELF'].'?src=/path/and/filename.jpg'."\n".'read Usage comments for details');
} elseif (eregi('^http\://', $phpThumb->src)) {
ob_start();
$HTTPurl = strtr($phpThumb->src, array(' '=>'%20'));
if ($fp = fopen($HTTPurl, 'rb')) {
$rawImageData = '';
do {
$buffer = fread($fp, 8192);
if (strlen($buffer) == 0) {
break;
}
$rawImageData .= $buffer;
} while (true);
fclose($fp);
$phpThumb->setSourceData($rawImageData, urlencode($phpThumb->src));
} else {
$fopen_error = strip_tags(ob_get_contents());
ob_end_clean();
if (ini_get('allow_url_fopen')) {
$phpThumb->ErrorImage('cannot open "'.$HTTPurl.'" - fopen() said: "'.$fopen_error.'"');
} else {
$phpThumb->ErrorImage('"allow_url_fopen" disabled');
}
}
ob_end_clean();
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[7]', __FILE__, __LINE__);
if (@$_GET['phpThumbDebug'] == '7') {
$phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
$phpThumb->GenerateThumbnail();
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[8]', __FILE__, __LINE__);
if (@$_GET['phpThumbDebug'] == '8') {
$phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
if ($phpThumb->config_allow_parameter_file && $phpThumb->file) {
$phpThumb->RenderToFile($phpThumb->ResolveFilenameToAbsolute($phpThumb->file));
if ($phpThumb->config_allow_parameter_goto && $phpThumb->goto && eregi('^(f|ht)tps?://', $phpThumb->goto)) {
// redirect to another URL after image has been rendered to file
header('Location: '.$phpThumb->goto);
exit;
}
} else {
if ((file_exists($phpThumb->cache_filename) && is_writable($phpThumb->cache_filename)) || is_writable(dirname($phpThumb->cache_filename))) {
$phpThumb->CleanUpCacheDirectory();
if ($phpThumb->RenderToFile($phpThumb->cache_filename)) {
chmod($phpThumb->cache_filename, 0644);
RedirectToCachedFile();
} else {
$phpThumb->DebugMessage('Failed: RenderToFile('.$phpThumb->cache_filename.')', __FILE__, __LINE__);
}
} else {
$phpThumb->DebugMessage('Cannot write to $phpThumb->cache_filename ('.$phpThumb->cache_filename.') because that directory ('.dirname($phpThumb->cache_filename).') is not writable', __FILE__, __LINE__);
}
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[9]', __FILE__, __LINE__);
if (@$_GET['phpThumbDebug'] == '9') {
$phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
$phpThumb->OutputThumbnail();
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -