function remote_filesize($uri,$user='',$pw='')
{
ob_start();
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, );
curl_setopt($ch, CURLOPT_NOBODY, );
if (!empty($user) && !empty($pw)) {
$headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$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);
//qq($head);
return isset($matches[]) ? $matches[] : 'unknown';
} 注意: $head = ob_get_contents(); 得到的是文件的头部信息:
HTTP/1.1 OK
Server: Tengine
Content-Type: image/jpeg
Content-Length:
Connection: keep-alive
Date: Tue, Dec :: GMT
Last-Modified: Tue, Dec :: GMT
Expires: Thu, Jan :: GMT
Cache-Control: max-age=
Accept-Ranges: bytes
Via: cache37.l2cm9-[,-,H], cache11.l2cm9-[,], kunlun7.cn119[,-,H], kunlun6.cn119[,]
Age:
X-Cache: HIT TCP_MEM_HIT dirn::
X-Swift-SaveTime: Thu, Dec :: GMT
X-Swift-CacheTime:
Timing-Allow-Origin: *
EagleId: 1bdd224614512746510381352e
 

PHP获取远程文件的大小,通过ob_get_contents实现的更多相关文章

  1. PHP 获取远程文件的大小的3种方法

    1.使用file_get_contents() <?php $file = file_get_contents($url); echo strlen($file); ?> 2. 使用get ...

  2. PHP学习笔记,curl,file_get_content,include和fopen四种方法获取远程文件速度测试.

    这几天在做抓取.发现用PHP的file_get_contents函数来获取远程文件的过程中总是出现失败,并且效率很低下.所以就做了个测试的demo来测试下PHP中各种方法获取文件的速度. 程序里面使用 ...

  3. curl获取远程文件内容

    curl获取远程文件内容 ** 获取远程文件内容 @param $url 文件http地址 * function fopen_url($url) { if (function_exists(& ...

  4. php获取远程文件内容的函数

    一个简单的php获取远程文件内容的函数代码,兼容性强.直接调用就可以轻松获取远程文件的内容,使用这个函数也可获取图片.代码如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  5. scp命令获取远程文件

    一.scp是什么? scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的,可能会稍微影响 ...

  6. http方式获取远程文件内容

    public class HttpServer { /// <summary> /// 读取远程文件的内容 /// </summary> /// <param name= ...

  7. python 获取视频文件的大小,时长等

    举例说明: import os import sys import xlwt from moviepy.editor import VideoFileClip file_dir = u"G: ...

  8. PHP获取远程文件的几种方式

    1.fopen() 2.file_get_contents() 3.fsocket() 4.curl()

  9. php获取远程文件大小

    获取本地文件大小filesize()就可以了,但是如何获取远程文件的大小呢? 这里介绍三个方法来获取远程文件的大小. 方法1:get_headers <?php get_headers($url ...

随机推荐

  1. http://www.easytest.xyz/login_action/

    http://www.easytest.xyz/login_action/一个挺牛逼的系统,有空学习下 https://www.cnblogs.com/1fengchen1/archive/2019/ ...

  2. python高级特性-迭代器

    凡是可作用于for循环的对象都是Iterable类型: 凡是可作用于next()函数的对象都是Iterator类型,它们表示一个惰性计算的序列: 集合数据类型如list.dict.str等是Itera ...

  3. dt6.0之mip改造-img正则替换mip-img

    最近没事,打算把自己的小项目改造为mip,进行测试学习,想把资讯栏目:http://zhimo.yuanzhumuban.cc/news/.全部改造为mip.但是MIP改造一项是:图片标签的改造.而且 ...

  4. Vue当中的this

    10事件绑定 methods当中的this就是Vue实例对象vm var vm = new Vue({ el: '#app', data: { num: 0 }, // 注意点: 这里不要忘记加逗号 ...

  5. vue中移动端自适应的postcss-plugin-px2rem插件

    flexible 主要是用来响应式改变根元素的字体大小 安装命令 npm install lib-flexible --save 在main.js里面导入命令import 'lib-flexible' ...

  6. nodejs查看本机hosts文件域名对应ip

    const dns = require('dns') dns.lookup('domainName', function(err, result) { console.log(result) }) r ...

  7. python 类 双下划线解析

    __getattr__用法:说明:这是python里的一个内建函数,当调用的属性或者方法不存在时,该方法会被调用调用不存在的属性调用不存在的方法

  8. Sublime 原版安装

    sublime text3 安装方法 ① 官网下载安装 https://www.sublimetext.com/3 ② 更改hosts文件 具体方法如下: windows系统的hosts文件在C:\W ...

  9. js通过html的url获取参数值

    function getUrlParameter(name){ name = name.replace(/[]/,"\[").replace(/[]/,"\[" ...

  10. Optimize Cube.js Performance with Pre-Aggregations

    转自:https://cube.dev/blog/high-performance-data-analytics-with-cubejs-pre-aggregations/ 可以了解 Pre-Aggr ...