File And Directory Manipulation In PHP (part 2) - Size Does Matter (Page 11 of 13 )
If you're looking for information on the total size of a partition or mount point, PHP offers the relatively-new disk_total_space() and
disk_free_space() functions, which return the total available space and total free space, in bytes, on a particular partition. Consider the following example, which demonstrates:
<?php
// set partition
$fs = "/";
// display available and used space
echo "Total available space: " . round(disk_total_space($fs) / (1024*1024))
. " MB\r\n"; echo "Total free space: " . round(disk_free_space($fs)
/ (1024*1024)) . " MB\r\n";
// calculate used space
$disk_used_space =
round((disk_total_space($fs) - disk_free_space($fs)) / (1024*1024));
echo "Total used space: " . $disk_used_space . " MB\r\n";
// calculate % used space
echo "% used space: " . round((disk_total_space($fs) -
disk_free_space($fs)) / disk_total_space($fs) * 100) . " %";
?>
Here's an example of what the output might look like:
Total available space: 7906 MB
Total free space: 4344 MB
Total used space: 3562 MB
% used space: 45 %
Next: In Process >>
More PHP Articles
More By icarus, (c) Melonfire