How can the filesize() function be utilized to display the name and size of a file in PHP?

To display the name and size of a file in PHP, you can use the filesize() function to get the size of the file and then display it along with the file name. This function returns the size of the file in bytes. You can use this information to create a message or display it in a user-friendly format.

<?php
$filename = "example.txt";
$filesize = filesize($filename);
echo "File name: " . $filename . "<br>";
echo "File size: " . $filesize . " bytes";
?>