php获取远程文件的大小

 
更多

php获取远程文件的大小,具体代码如下:

/*
**功能:获取远程文件的大小,返回值的单位是:字节
**函数参考自:http://www.phpernote.com/php-function/186.html
*/
function get_fileSize($url){
	if(!isset($url)||trim($url)==''){
		return '';
	}
	ob_start();
	$ch=curl_init($url);
	curl_setopt($ch,CURLOPT_HEADER,1);
	curl_setopt($ch,CURLOPT_NOBODY,1);
	$okay=curl_exec($ch);
	curl_close($ch);
	$head=ob_get_contents();
	ob_end_clean();
	$regex='/Content-Length:\s([0-9].+?)\s/';
	$count=preg_match($regex,$head,$matches);
	return isset($matches[1])&&is_numeric($matches[1])?$matches[1]:'';
}
打赏

本文固定链接: https://www.cxy163.net/archives/4512 | 绝缘体

该日志由 绝缘体.. 于 2013年05月23日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: php获取远程文件的大小 | 绝缘体
关键字: , , , ,

php获取远程文件的大小:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter