I currently look like the following tree structure:
+images +sub-directory -image1.jpg -image2.jpg +sub-directory-2 -image3.jpg -image4.jpg -some-image.jpg -another.jpg
<script> <?php //path to directory to scan. i have included a wildcard for a subdirectory $directory = "images/*/"; //get all image files with a .jpg extension. $images = glob("" . $directory . "*.jpg"); $imgs = ''; // create array foreach($images as $image){ $imgs[] = "$image"; } echo "var allImages = ".$imgs.";\n"; ?> console.log(allImages); </script>
Since I'm extremely new to php, I blindly register as Array() in the console.
In addition, I set $directory = "images/*/"; , which will receive all images only inside subfolders, but not receiving images inside the parent directory, which can be set to images/some-image.jpg , and I also wanted to get this.
I want all the images in such an array (when I use console.log(allImages); ):
['some-image.jpg','another.jpg','image1.jpg','image2.jpg','image3.jpg','image4.jpg']
source share