Skip to content

Instantly share code, notes, and snippets.

@ellygaytor
Created June 3, 2020 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellygaytor/2c40060d7a3a16559c1a7f0924376633 to your computer and use it in GitHub Desktop.
Save ellygaytor/2c40060d7a3a16559c1a7f0924376633 to your computer and use it in GitHub Desktop.
Dynamic item/directory listing in PHP
<?
$dirs = array_filter(glob('*'), 'is_dir');
echo "<ul>";
foreach ($dirs as $dir) {
$dataurl = dirname(__FILE__).'/'.$dir."/itemdata.json";
$url = $dataurl; // path to your JSON file
$data = file_get_contents($url);
$itemdata = json_decode($data);
if ($galdata->enabled == true) {
echo '<li><a href="'.$dir.'">'.$itemdata->item.'</a>';
echo "</li>";
}
}
echo '</ul>';
?>
{
"item": "Item Name",
"enabled": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment