本文整理汇总了PHP中waFiles::size方法的典型用法代码示例。如果您正苦于以下问题:PHP waFiles::size方法的具体用法?PHP waFiles::size怎么用?PHP waFiles::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waFiles
的用法示例。
在下文中一共展示了waFiles::size方法的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;
}
示例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;
}