zoukankan      html  css  js  c++  java
  • PHP 获取远程文件的大小

    $uri = 'http://localhost/ToyTest/X17-45990_1.dmg';
    
    echo remote_filesize($uri);
    
    function remote_filesize($uri,$user='',$pw=''){
        ob_start();
        $ch = curl_init($uri);
        curl_setopt($ch,CURLOPT_HEADER, 1);
        curl_setopt($ch,CURLOPT_NOBODY, 1);
        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/i';
        $count = preg_match($regex, $head, $matches);
    
        if (isset($matches[1])){
            $size = $matches[1];
        }else{
            $size = '0';
        }
    
        return $size;
    }

    注明:以上方法虽然方便,既能判断远程的文件是否存在,还能得到大小,但是并发

  • 相关阅读:
    Servlet深层知识
    HTTP协议
    Web开发中的主要概念
    Schema约束
    连接池基础
    Mysql基础3
    JDBC常用接口详解
    Mysql基础2
    Mysql基础1
    使用12c的DBCA创建数据库的时候报错TNS-04404
  • 原文地址:https://www.cnblogs.com/lsl8966/p/2908579.html
Copyright © 2011-2022 走看看