Hello All,
What I’d like to do is grab all images from a folder and post them dynamically to a web page. This code works fine if I hardcode in the exact folder, but the tricky part is getting it to work for all folders by looking at the URL and stripping it of the .php extension, which always matches the folder name exactly (a variable I have called $topic).
Does anyone have any ideas how to get this to work? I am fairly new to programming in general so I apologize if this isn’t very clear.
Here is the code:
<?php
$topic = basename($_SERVER[‘PHP_SELF’],“.php”).PHP_EOL;
$files = glob(‘img/’ . $topic . ‘/.’);
for ($i=0; $i<count($files); $i++) {
$num = $files[$i];
echo ‘<a href="’.$num.‘" target=“_blank”>’
.‘<img class=“thumb” src="’.$num.‘">’
.'</a> ';
}
?>