當前位置: 首頁>>代碼示例>>PHP>>正文


PHP timthumb::curlFH方法代碼示例

本文整理匯總了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;
     }
 }
開發者ID:sdgdsffdsfff,項目名稱:shipin,代碼行數:61,代碼來源:timthumb.php


注:本文中的timthumb::curlFH方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。