検索
ホームページphp教程php手册php获取文件大小的4种方法

在网上找了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元

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン