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";
?>
Related Questions
- In what ways can small internal projects benefit from adhering to coding standards and best practices, even if aesthetics are not a primary concern?
- How can PHP developers prevent "invisible" syntax errors in their code?
- What is the recommended approach to save form data before closing the form in PHP?