|
disk_free_space
Returns available space in directory
(PHP 4 >= 4.0.7, PHP 5)
Example 622. disk_free_space() example<?php Related Examples ( Source code ) » disk_free_space Examples ( Source code ) » Disk total space Code Examples / Notes » disk_free_spaceaidan
To make human readable file sizes, see this function: http://aidanlister.com/repos/v/function.size_readable.php mixar
This the right function is: function formatSize($size){ switch (true){ case ($size > 1099511627776): $size /= 1099511627776; $suffix = 'TB'; break; case ($size > 1073741824): $size /= 1073741824; $suffix = 'GB'; break; case ($size > 1048576): $size /= 1048576; $suffix = 'MB'; break; case ($size > 1024): $size /= 1024; $suffix = 'KB'; break; default: $suffix = 'B'; } return round($size, 2).$suffix; } djneoform
List all drives, free space, total space and percentage free. <? for ($i = 67; $i <= 90; $i++) { $drive = chr($i); if (is_dir($drive.':')) { $freespace = disk_free_space($drive.':'); $total_space = disk_total_space($drive.':'); $percentage_free = $freespace ? round($freespace / $total_space, 2) * 100 : 0; echo $drive.': '.to_readble_size($freespace).' / '.to_readble_size($total_space).' ['.$percentage_free.'%]<br />'; } } function to_readble_size($size) { switch (true) { case ($size > 1000000000000): $size /= 1000000000000; $suffix = 'TB'; break; case ($size > 1000000000): $size /= 1000000000; $suffix = 'GB'; break; case ($size > 1000000): $size /= 1000000; $suffix = 'MB'; break; case ($size > 1000): $size /= 1000; $suffix = 'KB'; break; default: $suffix = 'B'; } return round($size, 2).$suffix; } ?> nitrogen
Another easy way to convert bytes to human readable sizes would be this: <?php function HumanSize($Bytes) { $Type=array("", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"); $Index=0; while($Bytes>=1024) { $Bytes/=1024; $Index++; } return("".$Bytes." ".$Type[$Index]."bytes"); } ?> It simply takes the $Bytes and divides it by 1024 bytes untill it's no longer over or equal to 1024, meanwhile it increases the $Index to allocate which suffix belongs to the return (adding 'bytes' to the end to save some space). You can easily modify it so it's shorter, but I made it so it's more clearer. Nitrogen. ashraf m kaabi
and also you can know the used space , in this example : <? function disk_used_space($drive) { return disk_total_space("$drive:") - disk_free_space("$drive:"); } echo disk_used_space('C'); ?> |
Change Languagebasename chgrp chmod chown clearstatcache copy delete dirname disk_free_space disk_total_space diskfreespace fclose feof fflush fgetc fgetcsv fgets fgetss file_exists file_get_contents file_put_contents file fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype flock fnmatch fopen fpassthru fputcsv fputs fread fscanf fseek fstat ftell ftruncate fwrite glob is_dir is_executable is_file is_link is_readable is_uploaded_file is_writable is_writeable lchgrp lchown link linkinfo lstat mkdir move_uploaded_file parse_ini_file pathinfo pclose popen readfile readlink realpath rename rewind rmdir set_file_buffer stat symlink tempnam tmpfile touch umask unlink |