Determining File Sizes in PHP
The filesize function allows you to find
the size of a file in bytes. Example:
<?php
echo filesize('test.txt');
?>
The size in bytes can easily be converted to kilobytes:
<?php
echo filesize('test.txt') / 1024;
?>
And now let's convert it to megabytes:
<?php
echo filesize('test.txt') / (1024 * 1024);
?>
Let there be a file in the root of your site. Find out its size and display it on the screen.
Modify the previous task so that the file size is displayed in kilobytes.
Place some picture larger than a megabyte in the root of your site. Find out the size of this file and convert it to megabytes.
Place some movie larger than a gigabyte in the root of your site. Find out the size of this file and convert it to gigabytes.