获取远程文件大小的php函数
2015-01-24信息快讯网
用php实现获取远程文件大小的代码,需要的朋友可以参考下。
<?php
function getFileSize($url){
$url = parse_url($url);
if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){
fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1\r\n");
fputs($fp,"Host:$url[host]\r\n\r\n");
while(!feof($fp)){
$tmp = fgets($fp);
if(trim($tmp) == ''){
break;
}else if(preg_match('/Content-Length:(.*)/si',$tmp,$arr)){
return trim($arr[1]);
}
}
return null;
}else{
return null;
}
}
//调用方法
echo getFileSize("http://www.jb51.net/images/logo.gif")
?>
大家运行后,大小应该是4445字节。
php设计模式 Strategy(策略模式)
php设计模式 Observer(观察者模式)
php设计模式 Singleton(单例模式)
php设计模式 Command(命令模式)
php设计模式 Template (模板模式)
php统计文件大小,以GB、MB、KB、B输出
PHP与C#分别格式化文件大小的代码
Php Image Resize图片大小调整的函数代码
PHP stristr() 函数(不区分大小写的字符串查找)
PHP has encountered an Access Violation 错误的解决方法
PHP 编程安全性小结
基于Windows下Apache PHP5.3.1安装教程
PHP5.3.1 不再支持ISAPI
PhpMyAdmin中无法导入sql文件的解决办法
php实现的遍历文件夹下所有文件,编辑删除
PHP 裁剪图片成固定大小代码方法
PHP 上传文件大小限制
php获取某个目录大小的代码