本文整理汇总了PHP中phpthumb_functions::URLreadFsock方法的典型用法代码示例。如果您正苦于以下问题:PHP phpthumb_functions::URLreadFsock方法的具体用法?PHP phpthumb_functions::URLreadFsock怎么用?PHP phpthumb_functions::URLreadFsock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpthumb_functions
的用法示例。
在下文中一共展示了phpthumb_functions::URLreadFsock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SafeURLread
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;
}
示例2: SafeURLread
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;
}