当前位置: 首页>>代码示例>>PHP>>正文


PHP phpthumb_functions::URLreadFsock方法代码示例

本文整理汇总了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;
 }
开发者ID:mashbro,项目名称:Codefight-CMS,代码行数:76,代码来源:phpthumb.functions.php

示例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;
 }
开发者ID:kinj1987,项目名称:evo-league,代码行数:53,代码来源:phpthumb.functions.php


注:本文中的phpthumb_functions::URLreadFsock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。