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. Minio对象存储

    目录 Minio对象存储 1.概述 2.功能特性 3.2.多节点 3.3.分布式 4.分布式minio集群搭建 4.1.集群规划 4.3.编写集群启动脚本(所有节点) 4.4.编写服务脚本(所有节点) ...

  2. vmware联网解决方案:host-only共享上网

    一.需求说明 vmware通过桥接的方式可以上外网,但是虚拟机的IP地址必须和物理网卡在同一网段,上网环境不同虚拟机必须跟着换ip地址很麻烦,所以最好是采用host-only方式上网. 特别是做架构实 ...

  3. 30.第一个Linq 数据库查询

    使用Linq to Entity查询数据库 首先在项目中添加ADO.NET实体数据模型,如下 新建连接 勾选生成的表 点击完成即可看到两个建立的实体数据对象模型 模型生成好之后就可以直接使用了 Cus ...

  4. Caused by: java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [VCodeModel]

    2019-08-20 17:53:24,054 [ERROR] [http-nio-8047-exec-1] [HttpResult.java : 143] 系统异常 org.springframew ...

  5. python+selenium+chrome初级自动化操作

    例1. #coding=utf- from selenium import webdriver import os,time chromedriver = "C:\Users\AppData ...

  6. C# 7.0 中的新特性((.NET Framework 4.7 与 Visual Studio 2017 ))

    C#7.0 于 2017年3月 随 .NET 4.7 和 VS2017 发布. 一. out 变量(out variables) 以前我们使用out变量必须在使用前进行声明,C# 7.0 给我们提供了 ...

  7. 列举 Python2和Python3的区别?

    1.print 在python2中,print被视为一个语句而不是一个函数,python3中,print()被视为一个函数 2.整数的除法 在python2中,键入的任何不带小数的数字,将被视为整数的 ...

  8. 【Redis】Linux下Redis的安装

    Redis服务安装 主要有两种方式:apt安装和编译安装. 我采用的是apt安装,系统是ubuntu18.04,Redis version 5:4.0.9-1 在 Ubuntu 系统安装 Redi 可 ...

  9. C语言实现金字塔

    #include <stdio.h> int main(void) { int i=0, j =0, k= 0, line; printf("请输入金字塔的总行数:") ...

  10. PHP隐藏入口脚本文件index.php

    一.nginx下 隐藏入口文件时,配置nginx 首先得开启nginx pathinfo模式: location ~ \.php { #去掉$ root E:/phpStudy/WWW/tp/publ ...