Calculating file, directory, and disk sizes is a common task in all sorts of applications. This section introduces a number of standard PHP functions suited to this task. filesize() int filesize (string filename) The filesize() function returns the size, in bytes, of filename. An example follows: <?php This returns the following: --------------------------------------------File 852Chapter16R.rtf is 91815 bytes, or 89.66 kilobytes disk_free_space() float disk_free_space (string directory) The disk_free_space() function returns the available space, in bytes, allocated to the disk partition housing the directory specified by directory. An example follows: <?php This returns: --------------------------------------------2141.29 Note that the returned number is in megabytes (MB), because the value returned from disk_free_space() was divided by 1,048,576, which is equivalent to 1MB. disk_total_space() float disk_total_space (string directory) The disk_total_space() function returns the total size, in bytes, consumed by the disk partition housing the directory specified by directory. If you use this function in conjunction with disk_free_space(), it's easy to offer useful space allocation statistics: <?php This returns: --------------------------------------------Partition: / (Allocated: 3099.292 MB. Used: 343.652 MB.) Please check back for the next part of the series.
blog comments powered by Disqus |
|
|
|
|
|
|
|