Home  >  Article  >  Backend Development  >  php获取远程文件的大小

php获取远程文件的大小

WBOY
WBOYOriginal
2016-06-20 13:03:451005browse

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

<p>/*</p>**功能:获取远程文件的大小,返回值的单位是:字节<br />*/<br />function get_fileSize($url){<br />	if(!isset($url)||trim($url)==''){<br />		return '';<br />	}<br />	ob_start();<br />	$ch=curl_init($url);<br />	curl_setopt($ch,CURLOPT_HEADER,1);<br />	curl_setopt($ch,CURLOPT_NOBODY,1);<br />	$okay=curl_exec($ch);<br />	curl_close($ch);<br />	$head=ob_get_contents();<br />	ob_end_clean();<br />	$regex='/Content-Length:\s([0-9].+?)\s/';<br />	$count=preg_match($regex,$head,$matches);<br />	return isset($matches[1])&&is_numeric($matches[1])?$matches[1]:'';<br />}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn