當(dāng)前位置:首頁(yè) > IT技術(shù) > Web編程 > 正文

【PHP】獲取遠(yuǎn)程文件的字節(jié)大小
2021-09-15 15:05:59

 1 <?php
 2 
 3 /**
 4      * @description 獲取遠(yuǎn)程文件的字節(jié)大小
 5      * @param $url 遠(yuǎn)程文件地址
 6      * @return int|mixed 
 7      */
 8     function getFileSize($url){
 9         ob_start();
10         $ch = curl_init($url);
11         curl_setopt($ch, CURLOPT_HEADER, 1);
12         curl_setopt($ch, CURLOPT_NOBODY, 1);
13         curl_setopt($ch, CURLOPT_HTTPGET,1);
14         curl_exec($ch);
15         curl_close($ch);
16         $head = ob_get_contents();
17         ob_end_clean();
18         $regex = '/Content-Length:s([0-9].+?)s/';
19         preg_match($regex, $head, $matches);
20         return isset($matches[1]) && is_numeric($matches[1]) ? $matches[1] : 0;
21     }
22 
23 ?>

?

本文摘自 :https://www.cnblogs.com/

開(kāi)通會(huì)員,享受整站包年服務(wù)立即開(kāi)通 >