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


PHP waFiles::fp方法代碼示例

本文整理匯總了PHP中waFiles::fp方法的典型用法代碼示例。如果您正苦於以下問題:PHP waFiles::fp方法的具體用法?PHP waFiles::fp怎麽用?PHP waFiles::fp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在waFiles的用法示例。


在下文中一共展示了waFiles::fp方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: upload

 /**
  * Uploads a file from specified URL to a server directory.
  *
  * @param string $url URL from which a file must be retrieved
  * @param string $path Path for saving the downloaded file
  * @throws waException
  * @return int Size of saved file in bytes
  */
 public static function upload($url, $path)
 {
     $s = parse_url($url, PHP_URL_SCHEME);
     $w = stream_get_wrappers();
     if (in_array($s, $w) && ini_get('allow_url_fopen')) {
         if ($fp = @fopen($url, 'rb')) {
             if (self::$fp = @fopen($path, 'wb')) {
                 self::$size = stream_copy_to_stream($fp, self::$fp);
                 fclose(self::$fp);
             } else {
                 fclose($fp);
                 throw new waException('Error while open target file');
             }
             fclose($fp);
         } else {
             throw new waException("Error while open source file {$url}");
         }
     } elseif ($ch = self::curlInit($url)) {
         if (self::$fp = @fopen($path, 'wb')) {
             self::$size = 0;
             wa()->getStorage()->close();
             curl_exec($ch);
             fclose(self::$fp);
             if ($errno = curl_errno($ch)) {
                 $message = "Curl error: {$errno}# " . curl_error($ch) . " at [{$path}]";
                 curl_close($ch);
                 throw new waException($message);
             }
             $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             if ($response_code != 200) {
                 curl_close($ch);
                 throw new waException("Invalid server response with code {$response_code} while request {$url}");
             }
         }
         curl_close($ch);
     } else {
         throw new waException('There no available wrappers');
     }
     return self::$size;
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:48,代碼來源:waFiles.class.php

示例2: upload

 /**
  * Uploads a file from specified URL to a server directory.
  *
  * @param string $url URL from which a file must be retrieved
  * @param string $path Path for saving the downloaded file
  * @return int
  * @throws Exception
  * @throws waException
  */
 public static function upload($url, $path)
 {
     $s = parse_url($url, PHP_URL_SCHEME);
     $w = stream_get_wrappers();
     if (in_array($s, $w) && ini_get('allow_url_fopen')) {
         if ($fp = @fopen($url, 'rb')) {
             try {
                 if (self::$fp = @fopen($path, 'wb')) {
                     self::$size = stream_copy_to_stream($fp, self::$fp);
                     fclose(self::$fp);
                     $stream_meta_data = stream_get_meta_data($fp);
                     $headers = array();
                     if (isset($stream_meta_data["wrapper_data"]["headers"])) {
                         $headers = $stream_meta_data["wrapper_data"]["headers"];
                     } elseif (isset($stream_meta_data["wrapper_data"])) {
                         $headers = $stream_meta_data["wrapper_data"];
                     }
                     $header_matches = null;
                     //check server response codes (500/404/403/302/301/etc)
                     foreach ($headers as $header) {
                         if (preg_match('@http/\\d+\\.\\d+\\s+(\\d+)\\s+(.+)$@i', $header, $header_matches)) {
                             $response_code = intval($header_matches[1]);
                             $status_description = trim($header_matches[2]);
                             if ($response_code != 200) {
                                 throw new waException("Invalid server response with code {$response_code} ({$status_description}) while request {$url}");
                             }
                             break;
                         }
                     }
                 } else {
                     throw new waException('Error while open target file');
                 }
             } catch (waException $ex) {
                 fclose($fp);
                 waFiles::delete($path);
                 throw $ex;
             }
             fclose($fp);
         } else {
             throw new waException("Error while open source file {$url}");
         }
     } elseif ($ch = self::curlInit($url)) {
         if (self::$fp = @fopen($path, 'wb')) {
             self::$size = 0;
             wa()->getStorage()->close();
             curl_exec($ch);
             fclose(self::$fp);
             if ($errno = curl_errno($ch)) {
                 $message = "Curl error: {$errno}# " . curl_error($ch) . " at [{$path}]";
                 curl_close($ch);
                 throw new waException($message);
             }
             $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             if ($response_code != 200) {
                 curl_close($ch);
                 waFiles::delete($path);
                 throw new waException("Invalid server response with code {$response_code} while request {$url}");
             }
         }
         curl_close($ch);
     } else {
         throw new waException('There no available wrappers');
     }
     return self::$size;
 }
開發者ID:cjmaximal,項目名稱:webasyst-framework,代碼行數:74,代碼來源:waFiles.class.php


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