Remote file size without downloading file

前端 未结 14 1603
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 03:01

Is there a way to get the size of a remote file http://my_url/my_file.txt without downloading the file?

14条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 03:36

    one line best solution :

    echo array_change_key_case(get_headers("http://.../file.txt",1))['content-length'];
    

    php is too delicius

    function urlsize($url):int{
       return array_change_key_case(get_headers($url,1))['content-length'];
    }
    
    echo urlsize("http://.../file.txt");
    

提交回复
热议问题