php获取远程文件大小的函数
发布时间:2017-04-05 编辑:jiaochengji.com
分享一个可以获取远程文件大小的php函数,有兴趣的朋友可以参考下,学习下fsockopen的用法。
本节内容:
获取远程文件大小
例子:
复制代码 代码示例:
<?php
/**
* 获取远程文件大小
* by www.jbxue.com
*/
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.jbxue.com/test123.gif")
?>
/**
* 获取远程文件大小
* by www.jbxue.com
*/
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.jbxue.com/test123.gif")
?>
您可能感兴趣的文章:
php获取远程文件大小的函数
php 获取远程网页内容简单函数
php获取远程图片大小函数示例
PHP获取(读取)本地文件与远程文件内容示例
php读取远程文件的三种方法分享
php file_get_contents函数抓取页面信息的代码
php ftp上传,下载,删除服务器文件实例
php使用请求头信息获取远程图片大小
php函数get_headers是HEAD请求或GET请求
PHP 获取远程网页内容的代码
上一篇:php生成下载链接的快捷方式
下一篇:php数组与字符串间转换的例子
[关闭]