Show Images from folder to html page in PHP

0
123
PHP

This tutorial explains how to show Images of a folder or directory of Amazon Linux server to HTML page in PHP

 <table class="display table table-bordered table-striped" id="dynamic-table">
              <thead>
              <tr>
                  <th class="">Image</th>
                  <th class="">Name</th>
                  <th class="">URL</th> 
               
              </tr>
              </thead>
  <tbody>
              
<?php
$path="images/";
$files = glob("/var/www/html/".$path."*.*");
for ($i = 1; $i < count($files); $i++) {
    $image = $files[$i];
    $supported_file = array(
        'gif',
        'jpg',
        'jpeg',
        'png'
    );
 
    $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
    if (in_array($ext, $supported_file)) {
$image_name= '<img src="http://domain.com/images/'. basename($image) . '" style="max-width:100px;" alt="image" />'.'</br>';
$image_url= 'https://domain.com/web/images/'.basename($image)."</br>";

 echo "<tr class='gradeX'>"
            . "<td>".$image_name."</td>"
            . "<td>".basename($image)."</td>" 
             . "<td>".$image_url."</td>"
          
        . "</tr>";


} else {
continue;
}
}
?>
 
       </tbody>
              </table>

LEAVE A REPLY

Please enter your comment!
Please enter your name here