本文整理汇总了PHP中timthumb::curlFH方法的典型用法代码示例。如果您正苦于以下问题:PHP timthumb::curlFH方法的具体用法?PHP timthumb::curlFH怎么用?PHP timthumb::curlFH使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timthumb
的用法示例。
在下文中一共展示了timthumb::curlFH方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getURL
protected function getURL($url, $tempfile)
{
$this->lastURLError = false;
$url = preg_replace('/ /', '%20', $url);
if (function_exists('curl_init')) {
$this->debug(3, "Curl is installed so using it to fetch URL.");
self::$curlFH = fopen($tempfile, 'w');
if (!self::$curlFH) {
$this->error("Could not open {$tempfile} for writing.");
return false;
}
self::$curlDataWritten = 0;
$this->debug(3, "Fetching url with curl: {$url}");
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_WRITEFUNCTION, 'timthumb::curlWrite');
@curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
@curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
$curlResult = curl_exec($curl);
fclose(self::$curlFH);
$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($httpStatus == 404) {
$this->set404();
}
if ($httpStatus == 302) {
$this->error("External Image is Redirecting. Try alternate image url");
return false;
}
if ($curlResult) {
curl_close($curl);
return true;
} else {
$this->lastURLError = curl_error($curl);
curl_close($curl);
return false;
}
} else {
$img = @file_get_contents($url);
if ($img === false) {
$err = error_get_last();
if (is_array($err) && $err['message']) {
$this->lastURLError = $err['message'];
} else {
$this->lastURLError = $err;
}
if (preg_match('/404/', $this->lastURLError)) {
$this->set404();
}
return false;
}
if (!file_put_contents($tempfile, $img)) {
$this->error("Could not write to {$tempfile}.");
return false;
}
return true;
}
}