function ImageCreateFromStringReplacement(&$RawImageData, $DieOnErrors = false) { // there are serious bugs in the non-bundled versions of GD which may cause // PHP to segfault when calling ImageCreateFromString() - avoid if at all possible // when not using a bundled version of GD2 $gd_info = phpthumb_functions::gd_info(); if (strpos($gd_info['GD Version'], 'bundled') !== false) { return @ImageCreateFromString($RawImageData); } switch (substr($RawImageData, 0, 3)) { case 'GIF': $ICFSreplacementFunctionName = 'ImageCreateFromGIF'; break; case "ÿØÿ": $ICFSreplacementFunctionName = 'ImageCreateFromJPEG'; break; case "‰" . 'PN': $ICFSreplacementFunctionName = 'ImageCreateFromPNG'; break; default: $this->ErrorImage('Unknown image type identified by "' . substr($this->rawImageData, 0, 3) . '" (' . phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 3)) . ') in ImageCreateFromStringReplacement()'); break; } if ($tempnam = tempnam($this->config_temp_directory, 'pThumb')) { if ($fp_tempnam = @fopen($tempnam, 'wb')) { fwrite($fp_tempnam, $RawImageData); fclose($fp_tempnam); if ($ICFSreplacementFunctionName == 'ImageCreateFromGIF' && !function_exists($ICFSreplacementFunctionName)) { // Need to create from GIF file, but ImageCreateFromGIF does not exist if (@(include_once 'phpthumb.gif.php')) { // gif_loadFileToGDimageResource() cannot read from raw data, write to file first if ($tempfilename = tempnam($this->config_temp_directory, 'pThumb')) { if ($fp_tempfile = @fopen($tempfilename, 'wb')) { fwrite($fp_tempfile, $RawImageData); fclose($fp_tempfile); $gdimg_source = gif_loadFileToGDimageResource($tempfilename); unlink($tempfilename); return $gdimg_source; break; } else { $ErrorMessage = 'Failed to open tempfile in ' . __FILE__ . ' on line ' . __LINE__; } } else { $ErrorMessage = 'Failed to open generate tempfile name in ' . __FILE__ . ' on line ' . __LINE__; } } else { $ErrorMessage = 'Failed to include required file "phpthumb.gif.php" in ' . __FILE__ . ' on line ' . __LINE__; } } elseif (function_exists($ICFSreplacementFunctionName) && ($gdimg_source = $ICFSreplacementFunctionName($tempnam))) { // great unlink($tempnam); return $gdimg_source; } else { // GD functions not available // base64-encoded error image in GIF format $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7'; header('Content-type: image/gif'); echo base64_decode($ERROR_NOGD); exit; } } else { $ErrorMessage = 'Failed to fopen(' . $tempnam . ', "wb") in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpthumb.config.php'; } unlink($tempnam); } else { $ErrorMessage = 'Failed to generate tempnam() in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpthumb.config.php'; } if ($DieOnErrors && !empty($ErrorMessage)) { die($ErrorMessage); } return false; }
function ImageCreateFromStringReplacement(&$RawImageData, $DieOnErrors = false) { // there are serious bugs in the non-bundled versions of GD which may cause // PHP to segfault when calling ImageCreateFromString() - avoid if at all possible // when not using a bundled version of GD2 if (!phpthumb_functions::gd_version()) { if ($DieOnErrors) { if (!headers_sent()) { // base64-encoded error image in GIF format $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7'; header('Content-Type: image/gif'); echo base64_decode($ERROR_NOGD); } else { echo '*** ERROR: No PHP-GD support available ***'; } exit; } else { $this->DebugMessage('ImageCreateFromStringReplacement() failed: gd_version says "' . phpthumb_functions::gd_version() . '"', __FILE__, __LINE__); return false; } } if (phpthumb_functions::gd_is_bundled()) { $this->DebugMessage('ImageCreateFromStringReplacement() calling built-in ImageCreateFromString()', __FILE__, __LINE__); return @ImageCreateFromString($RawImageData); } if ($this->issafemode) { $this->DebugMessage('ImageCreateFromStringReplacement() failed: cannot create temp file in SAFE_MODE', __FILE__, __LINE__); return false; } switch (substr($RawImageData, 0, 3)) { case 'GIF': $ICFSreplacementFunctionName = 'ImageCreateFromGIF'; break; case "ÿØÿ": $ICFSreplacementFunctionName = 'ImageCreateFromJPEG'; break; case "‰" . 'PN': $ICFSreplacementFunctionName = 'ImageCreateFromPNG'; break; default: $this->DebugMessage('ImageCreateFromStringReplacement() failed: unknown fileformat signature "' . phpthumb_functions::HexCharDisplay(substr($RawImageData, 0, 3)) . '"', __FILE__, __LINE__); return false; break; } if ($tempnam = $this->phpThumb_tempnam()) { if ($fp_tempnam = @fopen($tempnam, 'wb')) { fwrite($fp_tempnam, $RawImageData); fclose($fp_tempnam); if ($ICFSreplacementFunctionName == 'ImageCreateFromGIF' && !function_exists($ICFSreplacementFunctionName)) { // Need to create from GIF file, but ImageCreateFromGIF does not exist ob_start(); if (!@(include_once dirname(__FILE__) . '/phpthumb.gif.php')) { $ErrorMessage = 'Failed to include required file "' . dirname(__FILE__) . '/phpthumb.gif.php" in ' . __FILE__ . ' on line ' . __LINE__; $this->DebugMessage($ErrorMessage, __FILE__, __LINE__); } ob_end_clean(); // gif_loadFileToGDimageResource() cannot read from raw data, write to file first if ($tempfilename = $this->phpThumb_tempnam()) { if ($fp_tempfile = @fopen($tempfilename, 'wb')) { fwrite($fp_tempfile, $RawImageData); fclose($fp_tempfile); $gdimg_source = gif_loadFileToGDimageResource($tempfilename); $this->DebugMessage('gif_loadFileToGDimageResource(' . $tempfilename . ') completed', __FILE__, __LINE__); $this->DebugMessage('deleting "' . $tempfilename . '"', __FILE__, __LINE__); unlink($tempfilename); return $gdimg_source; // break; } else { $ErrorMessage = 'Failed to open tempfile in ' . __FILE__ . ' on line ' . __LINE__; $this->DebugMessage($ErrorMessage, __FILE__, __LINE__); } } else { $ErrorMessage = 'Failed to open generate tempfile name in ' . __FILE__ . ' on line ' . __LINE__; $this->DebugMessage($ErrorMessage, __FILE__, __LINE__); } } elseif (function_exists($ICFSreplacementFunctionName) && ($gdimg_source = @$ICFSreplacementFunctionName($tempnam))) { // great $this->DebugMessage($ICFSreplacementFunctionName . '(' . $tempnam . ') succeeded', __FILE__, __LINE__); $this->DebugMessage('deleting "' . $tempnam . '"', __FILE__, __LINE__); unlink($tempnam); return $gdimg_source; } else { // GD functions not available, or failed to create image $this->DebugMessage($ICFSreplacementFunctionName . '(' . $tempnam . ') ' . (function_exists($ICFSreplacementFunctionName) ? 'failed' : 'does not exist'), __FILE__, __LINE__); if (isset($_GET['phpThumbDebug'])) { $this->phpThumbDebug(); } } } else { $ErrorMessage = 'Failed to fopen(' . $tempnam . ', "wb") in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php'; if ($this->issafemode) { $ErrorMessage = 'ImageCreateFromStringReplacement() failed in ' . __FILE__ . ' on line ' . __LINE__ . ': cannot create temp file in SAFE_MODE'; } $this->DebugMessage($ErrorMessage, __FILE__, __LINE__); } $this->DebugMessage('deleting "' . $tempnam . '"', __FILE__, __LINE__); @unlink($tempnam); } else { $ErrorMessage = 'Failed to generate phpThumb_tempnam() in ' . __FILE__ . ' on line ' . __LINE__ . "\n" . 'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php'; if ($this->issafemode) { $ErrorMessage = 'ImageCreateFromStringReplacement() failed in ' . __FILE__ . ' on line ' . __LINE__ . ': cannot create temp file in SAFE_MODE'; } } if ($DieOnErrors && $ErrorMessage) { return $this->ErrorImage($ErrorMessage); } return false; }
@fclose($fptr); @chmod($filetmp, 0777); } $ini_val = @phpversion() >= '4.0.0' ? 'ini_get' : 'get_cfg_var'; if (@$ini_val('open_basedir') != '') { if (@phpversion() < '4.0.3') { message_die(GENERAL_ERROR, 'open_basedir is set and your PHP version does not allow move_uploaded_file<br /><br />Please contact your server admin', '', __LINE__, __FILE__); } $move_file = 'move_uploaded_file'; } else { $move_file = 'copy'; } // if it is a gif or a png to convert if ($pic_subtype == 'gif') { include_once $phpbb_root_path . 'auction/graphic_files/phpthumb.gif.php'; $src = gif_loadFileToGDimageResource($filetmp); @imagejpeg($src, $phpbb_root_path . AUCTION_PICTURE_UPLOAD_PATH . $pic_filename, 80); @unlink($filetmp); Imagedestroy($src); } else { if ($pic_subtype == 'png') { $move_file($filetmp, $phpbb_root_path . AUCTION_PICTURE_UPLOAD_PATH . $pic_filename); @chmod($phpbb_root_path . AUCTION_PICTURE_UPLOAD_PATH . $pic_filename, 0777); $read_function = 'imagecreatefrompng'; $src = @$read_function($phpbb_root_path . AUCTION_PICTURE_UPLOAD_PATH . $pic_filename); @unlink($phpbb_root_path . AUCTION_PICTURE_UPLOAD_PATH . $pic_filename); @imagejpeg($src, $phpbb_root_path . AUCTION_PICTURE_UPLOAD_PATH . $pic_filename, 80); Imagedestroy($src); } else { $move_file($filetmp, $phpbb_root_path . AUCTION_PICTURE_UPLOAD_PATH . $pic_filename); @unlink($filetmp);