For a non-looping way to add symbols to a number of bytes:
<?php
function getSymbolByQuantity($bytes) {
$symbols = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
$exp = floor(log($bytes)/log(1024));
return sprintf('%.2f '.$symbol[$exp], ($bytes/pow(1024, floor($exp))));
}disk_total_space
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
disk_total_space
Референца за `function.disk-total-space.php` со подобрена типографија и навигација.
disk_total_space
(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)
disk_total_space — Враќа вкупна големина на датотечен систем или партиција на диск
= NULL
Даден стринг што содржи директориум, оваа функција ќе врати вкупен број на бајти на соодветниот датотечен систем или партиција на диск.
Параметри
directory-
Директориум на файловиот систем или партицијата на дискот.
Вратени вредности
Враќа вкупен број на бајти како float или false при неуспех.
Примери
Пример #1 disk_total_space() example
<?php
// $ds contains the total number of bytes available on "/"
$ds = disk_total_space("/");
// On Windows:
$ds = disk_total_space("C:");
$ds = disk_total_space("D:");
?>Белешки
Забелешка: Оваа функција нема да работи на Оваа опција овозможува fopen обвивки свесни за URL-и кои овозможуваат пристап до URL објекти како датотеки. Стандардни обвивки се обезбедени за пристап до бидејќи датотеката што треба да се испита мора да биде достапна преку датотечниот систем на серверот.
Белешки од корисници 5 белешки
Beware of empty files!
<?php
// Wrong
$exp = floor(log($bytes) / log(1024));
//Correct
$exp = $bytes ? floor(log($bytes) / log(1024)) : 0;
?>"filesystem or disk partition" does not equal "directory" for Windows. Thanks.function roundsize($size){
$i=0;
$iec = array("B", "Kb", "Mb", "Gb", "Tb");
while (($size/1024)>1) {
$size=$size/1024;
$i++;}
return(round($size,1)." ".$iec[$i]);}To find the total size of a file/directory you have to differ two situations:
(on Linux/Unix based systems only!?)
you are interested:
1) in the total size of the files in the dir/subdirs
2) what place on the disk your dir/subdirs/files uses
- 1) and 2) normaly differs, depending on the size of the inodes
- mostly 2) is greater than 1) (in the order of any kB)
- filesize($file) gives 1)
- "du -ab $file" gives 2)
so you have to choose your situation!
on my server I have no rights to use "exec du" in the case of 2), so I use:
$s = stat($file);
$size = $s[11]*$s[12]/8);
whitch is counting the inodes [12] times the size of them in Bits [11]
hopes this helps to count the used disk place in a right way... :-)
Andreas Dick