The following code is part of an HTML file used to display images. There are several lines before his but i cut to the chase with the only working part I need help with. I need to get it to add a line feed <br> only before it displays a .jpg file.
The contents of the folder are all png image files except for the index images which are jpg. I am trying to get them to show up with all the png under the index they belong to.
If working properly, it should start by adding a line feed before displaying the first index file named "A.jpg", then display A.jpg followed by all the the A***.png files, then add a linefeed before displaying the "B.jpg index" followed by the B***.png files.
I am pretty sure that this needs to happen in the last 4 lines of code but I cannot seem to get the <br> to work dependent on the type of file.
I need to add a <br> to the front of the display only if the file-type is a jpg.
As it is now, it displays the files end to end with the title indexes being followed by their png's then the next index file with no break.
This works as is but I would like to try getting it a little better organized for display purposes.
<?php
$folder_path = 'images/'; //image's folder path
$num_files = glob($folder_path . "*.{JPG,jpg,gif,png,bmp}", GLOB_BRACE);
$folder = opendir($folder_path);
if($num_files > 0)
{
while(false !== ($file = readdir($folder)))
{
$file_path = $folder_path.$file;
$extension = strtolower(pathinfo($file ,PATHINFO_EXTENSION));
if($extension=='jpg' || $extension =='png' || $extension == 'gif' || $extension == 'bmp')
{
$txtfile_temp = basename($file_path, ".".$extension).PHP_EOL;
$txtfile = $folder_path.trim($txtfile_temp).".txt";
$fp = fopen($txtfile, "r");
if ($fp == false)
{
$file_path = "Failed to open ".$txtfile;
$line = "Failed to open ".$txtfile;
}
else
{
$line = fgets($fp);
fclose($fp);
}
?>
<a href="<?php echo "".$line; ?>"><img src="<?php echo $file_path; ?>" height="300" /></a>
<?php
}