What are some best practices for displaying file properties, such as name and size, under an image in PHP?

When displaying file properties under an image in PHP, it is important to ensure that the information is presented in a clear and organized manner. One best practice is to use a table or list format to display the file name and size. Additionally, it is recommended to format the file size in a human-readable format, such as KB or MB, for better readability.

<?php
// File properties
$filename = "example.jpg";
$filesize = filesize($filename);

// Convert file size to human-readable format
if ($filesize >= 1073741824) {
    $filesize = number_format($filesize / 1073741824, 2) . ' GB';
} elseif ($filesize >= 1048576) {
    $filesize = number_format($filesize / 1048576, 2) . ' MB';
} elseif ($filesize >= 1024) {
    $filesize = number_format($filesize / 1024, 2) . ' KB';
} else {
    $filesize = $filesize . ' bytes';
}

// Display file properties under the image
echo '<img src="' . $filename . '" alt="Image">';
echo '<ul>';
echo '<li><strong>File Name:</strong> ' . $filename . '</li>';
echo '<li><strong>File Size:</strong> ' . $filesize . '</li>';
echo '</ul>';
?>