php4如何获取远程文件大小类
php5有get_headers非常好用,因为他可以直接读取远程文件的信息,而不用把整个文件读取到服务器。但是现在很多web服务器都不支持php5,下面我们就来看一个关于php4获取远程服务器文件大小的实例类吧。
php教程4如何获取远程文件大小类
/*
php5有get_headers非常好用,因为他可以直接读取远程文件的信息,而不用把整个文件读取到服务器。但是现在很多web服务器都不支持php5,下面我们就来看一个关于php4获取远程服务器文件大小的实例类吧。
*/
if(!function_exists(get_headers))
{
function get_headers(http://pic1.phprm.com/2013/09/05/$url.jpg,$format=0)
{
$url=parse_url($url);
$end = "rnrn";
$fp = fsockopen($url[host], (empty($url[port])?80:$url[port]), $errno, $errstr, 30);
if ($fp)
{
$out = "get / http/1.1rn";
$out .= "host: ".$url[host]."rn";
$out .= "connection: closernrn";
$var = ;
fwrite($fp, $out);
while (!feof($fp))
{
$var.=fgets($fp, 1280);
if(strpos($var,$end))
break;
}
fclose($fp);$var=preg_replace("/rnrn.*$/",,$var);
$var=explode("rn",$var);
if($format)
{
foreach($var as $i)
{
if(preg_match(/^([a-za-z -]+): +(.*)$/,$i,$parts))
$v[$parts[1]]=$parts[2];
}
return $v;
}
else
return $var;
}
}
}
文章网址:http://www.phprm.com/frame/php1005080.html
随意转载^^但请附上教程地址。