What are some best practices for displaying multiple photos from a folder on a website using PHP without creating layout tables?
When displaying multiple photos from a folder on a website using PHP, it is best to use a grid layout with CSS instead of relying on layout tables for better responsiveness and flexibility. One way to achieve this is by using PHP to loop through the image files in the folder and dynamically generate HTML markup for each image.
<?php
$folder_path = 'path/to/folder/';
$files = glob($folder_path . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
if ($files) {
echo '<div class="photo-grid">';
foreach ($files as $file) {
echo '<img src="' . $file . '" alt="Photo">';
}
echo '</div>';
} else {
echo 'No photos found.';
}
?>