½¨Õ¾Ñ§ - ÇáËɽ¨Õ¾´Ó´Ë¿ªÊ¼£¡

½¨Õ¾Ñ§-¸öÈ˽¨Õ¾Ö¸ÄÏ,ÍøÒ³ÖÆ×÷,ÍøÕ¾Éè¼Æ,ÍøÕ¾ÖÆ×÷½Ì³Ì

µ±Ç°Î»ÖÃ: ½¨Õ¾Ñ§ > ÍøÕ¾¿ª·¢ > PHP½Ì³Ì >

phpÈçºÎ»ñÈ¡ÉÏ´«Îļþ´óС

ʱ¼ä:2019-08-28 15:27À´Ô´:PHPÖÐÎÄÍø ×÷Õß:Öí¸ç µã»÷: ´Î
Èç¹ûÖ»ÊÇ»ñÈ¡ÎļþµÄ×Ö½ÚÊý£¬ÎÒÃÇ¿ÉÒÔÖ±½ÓʹÓÃphpµÄ filesize()º¯ÊýÀ´»ñÈ¡¡£µ±È»Èç¹ûÐèÒª»ñÈ¡ÎļþµÄ´óС²¢ÇÒÏÔʾÕý³£´óС¸ñʽ£¬ÎÒÃÇÖ»ÐèÒªÔÚÕâ¸öº¯ÊýµÄ»ù´¡ÉϽøÐÐһЩ¼òµ¥ÔËËã¾ÍÐÐÁË¡£

¡¡¡¡¶ÔÓÚ³õÈëÃŵÄPHPÐÂÊÖÀ´Ëµ£¬PHP»ñÈ¡Îļþ´óСÕâ¸ö¹¦ÄÜʵÏÖ£¬»òÐíÓÐÒ»¶¨µÄÄѶȡ£µ«ÊÇÏàÐÅÐÂÊÖС°×ÃÇÔÚ¿´¹ý±¾ÆªÎÄÕ½éÉܺó£¬Ò»¶¨ÄÜÇáËÉÕÆÎÕPHP»ñÈ¡Îļþ´óСµÄÖØҪ֪ʶ£¡

ÍƼö½Ì³Ì£ºPHPÊÓƵ½Ì³Ì

ÏÂÃæÎÒÃÇͨ¹ý¾ßÌåµÄ´úÂëʾÀý£¬Îª´ó¼ÒÏêϸµÄ·ÖÎö½éÉÜPHP»ñÈ¡Îļþ´óСµÄ·½·¨¡£

Ò»¡¢Ê×ÏÈÈç¹ûÄãÖ»ÐèÒª»ñÈ¡ÎļþµÄ×Ö½ÚÊý

Äã¿ÉÒÔÖ±½Óͨ¹ýPHP filesizeº¯ÊýÀ´»ñÈ¡£¬´úÂëÈçÏ£º

echo filesize("upload.php");

ͨ¹ýä¯ÀÀÆ÷·ÃÎÊ£¬Êä³ö½á¹ûÈçÏÂͼ£º

php11.png

¡¡¡¡´ÓÉÏͼÖпÉÒÔ¿´µ½£¬ÎÒÃÇÖ±½ÓÊä³ö»ñÈ¡µÄÎļþ´óСÊÇ1614×Ö½Ú£¬¶øÔÚupload.phpÊôÐÔÖв鿴µ½ÆäÎļþ´óСҲ¾ÍÊÇ1614×Ö½Ú¡£ÎÒÃǶ¼ÖªµÀÎļþ´óС£¬³ýÁËÓÃ×Ö½ÚÊý±íʾ¸ü³£¼ûµÄÊÇÓÃKB¡¢MB¡¢GB¡¢TBÕâЩµ¥Î»±íʾ¡£

¶þ¡¢ÄÇôÈç¹ûÎÒÃÇÏëÒª»ñÈ¡Îļþ´óС²¢ÇÒÊÇÕý³£´óСµÄ¸ñʽÏÔʾ£¬¸ÃÈçºÎ²Ù×÷ÄØ£¿

ÏÂÃæÎÒÃǽéÉÜÒ»¸ö·Ç³£¼òµ¥µÄ·â×°»ñÈ¡Õý³£´óСµÄ·½·¨¡£

PHP·â×°»ñÈ¡Õý³£´óС·½·¨µÄ¾ßÌå´úÂëʾÀýÈçÏ£º

<?php
$size = filesize("upload.php");
function trans_byte($byte)
{
    $KB = 1024;
    $MB = 1024 * $KB;
    $GB = 1024 * $MB;
    $TB = 1024 * $GB;
    if ($byte < $KB) {
        return $byte . "B";
    } elseif ($byte < $MB) {
        return round($byte / $KB, 2) . "KB";
    } elseif ($byte < $GB) {
        return round($byte / $MB, 2) . "MB";
    } elseif ($byte < $TB) {
        return round($byte / $GB, 2) . "GB";
    } else {
        return round($byte / $TB, 2) . "TB";
    }
}
echo trans_byte($size);

¡¡¡¡Ôڴ˶δúÂëÖУ¬ÎÒÃÇÏȶ¨ÒåÁËÒ»¸ö$size±äÁ¿À´»ñÈ¡upload.phpÎļþµÄ×Ö½Ú´óС£¬È»ºó´´½¨Ò»¸öÃûΪfilesizeµÄ·½·¨£¬Õâ¸ö·½·¨¾ÍÊÇÓÃÀ´½«×Ö½Ú´óСת»»ÎªÕý³£´óС¸ñʽ¡£

¡¡¡¡´ó¼ÒÓ¦¸Ã¶¼ÖªµÀ¼ÆËã»ú¼ÆÊýʹÓõĶ¼ÊǶþ½øÖÆ£¬ËüÊÇÒÔ2µÄ´Î·½ÊýÀ´¼ÆËãµÄ¡£1KB=2µÄ10´Î·½£½1024B£»1MB=2µÄ20´Î·½£½1024*1024B£½1024KB£»GB¡¢TBת»»ÒÔ´ËÀàÍÆ¡£

¡¡¡¡ËùÒÔÎÒÃÇÔÚfilesizeÕâ¸ö·½·¨ÖУ¬Ê×Ïȶ¨ÒåÁËÉÏÊö´úÂëÖеÄ$KB ¡¢$MB ¡¢$GB ¡¢$TBËĸö±äÁ¿¡£È»ºóÓÃif...elseifÌõ¼þÓï¾ä¶ÔÎļþ×Ö½Ú´óС½øÐÐÖð²½Åжϣ¬²¢ÇÒÓÃPHP roundº¯Êý¶ÔÎļþ´óСֵ½øÐб£ÁôÁ½Î»Ð¡ÊýµÄ²Ù×÷¡£

¡¡¡¡ÄÇôÎÒÃǶÔÉÏÊö·â×°»ñÈ¡ÎļþÕý³£´óСµÄfilesize·½·¨½øÐвâÊÔ£¬Í¨¹ýä¯ÀÀÆ÷·ÃÎÊphp»ñÈ¡Îļþ´óС½á¹ûÈçÏÂͼ£º

php12.png

¡¡¡¡´ÓÉÏͼ¿ÉÒÔ·¢ÏÖ£¬Í¨¹ýÎÒÃÇ×Ô¼º·â×°µÄfilesize·½·¨ÒѾ­¿ÉÒÔʵÏÖphp¼ÆËãÎļþ´óС²¢Çҳɹ¦µØ»ñÈ¡µ½ÎļþÕý³£´óСµÄ¹¦ÄÜ¡£¿ÉÄÜÓÐЩÅóÓÑ·¢ÏÖÁË»ñÈ¡µÄ´óС¸úÎļþ±¾ÉíÊôÐԵĴóС²»ÊÇÍêÈ«Ò»ÑùµÄ£¬Æäʵͨ¹ýPHP·½·¨»ñÈ¡´óСʱ´æÔÚÒ»µãÎó²îÊǷdz£Õý³£µÄ£¬¿ÉÒÔºöÂÔ²»¼Æ¡£

¡¡¡¡ÄÇôÒÔÉϾÍÊǹØÓÚPHP»ñÈ¡Îļþ´óС·½·¨Ïê½âÒÔ¼°½«Îļþ×Ö½Ú»ñȡת»»ÎªKB ¡¢MB ¡¢GB ¡¢TB¸ñʽ¼´Õý³£´óСÏÔʾµÄ·â×°·½·¨½éÉÜ£¡·Ç³£Ç³ÏÔÒ׶®£¬Ï£Íû¶ÔÓÐÐèÒªµÄÅóÓÑÓÐÒ»¶¨µÄ°ïÖú£¡

(ÔðÈα༭£ºadmin)
Ö¯ÃζþάÂëÉú³ÉÆ÷
¶¥Ò»ÏÂ
(0)
0%
²ÈÒ»ÏÂ
(0)
0%
------·Ö¸ôÏß----------------------------
·¢±íÆÀÂÛ
Çë×Ô¾õ×ñÊØ»¥ÁªÍøÏà¹ØµÄÕþ²ß·¨¹æ£¬ÑϽû·¢²¼É«Çé¡¢±©Á¦¡¢·´¶¯µÄÑÔÂÛ¡£
ÆÀ¼Û:
񡀂:
Óû§Ãû: ÑéÖ¤Âë:µã»÷ÎÒ¸ü»»Í¼Æ¬