Created
June 3, 2020 18:48
-
-
Save ellygaytor/2c40060d7a3a16559c1a7f0924376633 to your computer and use it in GitHub Desktop.
Dynamic item/directory listing in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"item": "Item Name", | |
"enabled": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment