Home > php教程 > php手册 > body text

php获取远程文件大小,

WBOY
Release: 2016-06-13 08:52:54
Original
1071 people have browsed it

php获取远程文件大小,

本文实例讲述了php获取远程文件大小的方法,分享给大家供大家参考。具体实现方法如下:

/* 
**功能:获取远程文件的大小,返回值的单位是:字节 
*/ 
function get_fileSize($url){ 
  if(!isset($url)||trim($url)==''){ 
    return ''; 
  } 
  ob_start(); 
  $ch=curl_init($url); 
  curl_setopt($ch,CURLOPT_HEADER,1); 
  curl_setopt($ch,CURLOPT_NOBODY,1); 
  $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); 
  return isset($matches[1])&&is_numeric($matches[1])?$matches[1]:''; 
} 
Copy after login

希望本文所述对大家的php程序设计有所帮助,大家能够喜欢小便的文章,大家共同进步。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template