<?php $file = 'demo.jpeg'; echo filesize($file); ?>
This function is for use on local files only and will not work on remote files but what you can do is download the file to a temporary folder and then get the size that way.
Also note that file results are returned in bytes so would look something like 176924 which is not easily readable but you can convert it to KB or MB or more rounding the numbers up or down to the amount after the decimal point of your choice.
<?php $file = 'demo.jpeg'; $bytes = filesize($file); $kbytes = $bytes / 1024; $mbytes = $kbytes / 1024; echo $file." is equal too:-
"; echo round($bytes, 3)." bytes
"; echo round($kbytes, 2)." kilobyte
"; echo round($mbytes, 3)." megabyte
Why would you use this?
Well imagine you were offering a file for download which you updated often but also wanted to show the user it’s file size this would be ideal as it would change each time the file changed!