Code needs to be written so that it can be read and understood by other people, not just be functional.
The glob() function in PHP allows you to search folders and put the results into an array based on basic filtering. glob() https://www.php.net/manual/en/function.glob.php https://www.w3schools.com/php/func_filesystem_glob.asp glob.php glob.php (with Image Embed)
The pathinfo() function allows you to turn a filepath into an Array and then interact with the keys of the Array. You can grab the Filename, Extension, Folder Name and Basename. pathinfo() https://www.php.net/manual/en/function.pathinfo.php https://www.w3schools.com/php/func_filesystem_pathinfo.asp pathinfo.php