Skip to content

Instantly share code, notes, and snippets.

@patrickmaciel
Last active January 4, 2016 04:08
Show Gist options
  • Save patrickmaciel/8566155 to your computer and use it in GitHub Desktop.
Save patrickmaciel/8566155 to your computer and use it in GitHub Desktop.
Dynamic images by folder name in url
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?folder=$1 [L,QSA]
</IfModule>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Show images</title>
</head>
<body>
<ul>
<li><a href="uk">UK</a></li>
<li><a href="us">US</a></li>
</ul>
<?php
if (isset($_GET['folder'])):
$folder = $_GET['folder'];
$dir = new DirectoryIterator('assets' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $folder);
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$pages[] = $fileinfo->getPathname(); ?>
<img src="<?php echo $fileinfo->getPathname() ?>" alt="<?php echo $fileinfo->getFilename() ?>" width="300px">
<?php }
}
endif;
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment