在网上找了4种获取文件大小的方法 记录起来。。。。
方法一:header<?php <br />
get_headers($url,true); <br>
<br>
//返回结果 <br>
Array <br>
( <br>
[0] => HTTP/1.1 200 OK <br>
[Date] => Sat, 29 May 2004 12:28:14 GMT <br>
[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux) <br>
[Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT <br>
[ETag] => "3f80f-1b6-3e1cb03b" <br>
[Accept-Ranges] => bytes <br>
<strong>[Content-Length] => 438 </strong> <br>
[Connection] => close <br>
[Content-Type] => text/html <br>
) <br>
?>
方法二function getFileSize($url) <br>
{ <br>
$url = parse_url($url); <br>
if($fp = @fsockopen($url['host'],emptyempty($url['port'])?80:$url['port'],$error)) <br>
{ <br>
fputs($fp,"GET ".(emptyempty($url['path'])?'/':$url['path'])." HTTP/1.1\r\n"); <br>
fputs($fp,"Host:$url[host]\r\n\r\n"); <br>
while(!feof($fp)) <br>
{ <br>
$tmp = fgets($fp); <br>
if(trim($tmp) == '') <br>
{ <br>
break; <br>
} <br>
elseif(preg_match('/Content-Length:(.*)/si',$tmp,$arr)) <br>
{ <br>
return trim($arr[1]); <br>
} <br>
} <br>
return null; <br>
} <br>
else <br>
{ <br>
return null; <br>
} <br>
}
方法三:function remote_filesize($uri,$user='',$pw='') <br>
{ <br>
// start output buffering <br>
ob_start(); <br>
// initialize curl with given uri <br>
$ch = curl_init($uri); <br>
// make sure we get the header <br>
curl_setopt($ch, CURLOPT_HEADER, 1); <br>
// make it a http HEAD request <br>
curl_setopt($ch, CURLOPT_NOBODY, 1); <br>
// if auth is needed, do it here <br>
if (!emptyempty($user) && !emptyempty($pw)) <br>
{ <br>
$headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw)); <br>
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); <br>
} <br>
$okay = curl_exec($ch); <br>
curl_close($ch); <br>
// get the output buffer <br>
$head = ob_get_contents(); <br>
// clean the output buffer and return to previous <br>
// buffer settings <br>
ob_end_clean(); <br>
<br>
echo '<br>head-->'.$head.''; <br>
<br>
// gets you the numeric value from the Content-Length <br>
// field in the http header <br>
$regex = '/Content-Length:\s([0-9].+?)\s/'; <br>
$count = preg_match($regex, $head, $matches); <br>
<br>
// if there was a Content-Length field, its value <br>
// will now be in $matches[1] <br>
if (isset($matches[1])) <br>
{ <br>
$size = $matches[1]; <br>
} <br>
else <br>
{ <br>
$size = 'unknown'; <br>
} <br>
//$last=round($size/(1024*1024),3); <br>
//return $last.' MB'; <br>
return $size; <br>
}
方法四:$fCont = file_get_contents("http://www.weiyeying.cn/"); <br>
echo strlen($fCont)/1024;
AD:真正免费,域名+虚机+企业邮箱=0元

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

드림위버 CS6
시각적 웹 개발 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

WebStorm Mac 버전
유용한 JavaScript 개발 도구
