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 (eregi('302 [a-z ]+; Location\\: (http.*)', $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;
 }
 function SafeURLread($url, &$error)
 {
     $error = '';
     $parsed_url = @parse_url($url);
     $rawData = phpthumb_functions::URLreadFsock(@$parsed_url['host'], @$parsed_url['path'], $errstr, true, @$parsed_url['port'] ? @$parsed_url['port'] : 80);
     $error .= 'Error: ' . $errstr . "\n" . $url;
     if ($rawData === false) {
         return false;
     } elseif ($rawData === null) {
         // fall through
     } else {
         return $rawData;
     }
     $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 = '';
         ob_start();
         if ($fp = fopen($url, 'rb')) {
             do {
                 $buffer = fread($fp, 8192);
                 $rawData .= $buffer;
             } while (strlen($buffer) > 0);
             fclose($fp);
         } else {
             $error .= trim(strip_tags(ob_get_contents()));
         }
         ob_end_clean();
         if (!$error) {
             return $rawData;
         }
         $error .= '; "allow_url_fopen" enabled but returned no data; ';
     } else {
         $error .= '"allow_url_fopen" disabled; ';
     }
     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);
         $rawData = curl_exec($ch);
         curl_close($ch);
         if (strlen($rawData) > 0) {
             return $rawData;
         }
         $error .= 'CURL available but returned no data; ';
     } else {
         $error .= 'CURL unavailable; ';
     }
     return false;
 }