Created
May 14, 2021 08:10
-
-
Save NachoToast/a9c198d6eec9bfe44446ae62cf5ac2c8 to your computer and use it in GitHub Desktop.
Get array of files and multidimensional array of folders and files (1 directory deep) in a directory.
This file contains hidden or 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
var files = | |
<?php | |
$files = array(); | |
foreach (glob('*.html') as $filename) { | |
$files[] = pathinfo($filename)['filename'] . "." . pathinfo($filename)['extension']; | |
} | |
echo json_encode($files); | |
?>, | |
folders = | |
<?php | |
$folders = array(); | |
foreach (glob('*', GLOB_ONLYDIR) as $directory) { | |
$p = pathinfo($directory)['filename']; | |
$items = 0; | |
foreach (glob("$p/*.html") as $filename) { | |
$folders[$p][$items] = pathinfo($filename)['filename'] . "." . pathinfo($filename)['extension']; | |
$items++; | |
} | |
} | |
echo json_encode($folders); | |
?>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment