【PHP】获取远程文件的字节大小
2021/9/15 14:34:47
本文主要是介绍【PHP】获取远程文件的字节大小,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 <?php 2 3 /** 4 * @description 获取远程文件的字节大小 5 * @param $url 远程文件地址 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 ?>
这篇关于【PHP】获取远程文件的字节大小的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。
- 2023-10-13唱衰这么多年,PHP 仍然还是你大爷!
- 2023-07-25PHP8,性能更好,语法更好,类型安全更完善