building a site for a client who wants to be able to just upload files to their server (with specific naming) and have them parsed for the site content. I got it working great for the first initial folder but I am having a hard time exporting the subfolder files are their own array. Here is the code:
$files = scandir(getcwd()); foreach ($files as $file) { if(is_file($file)) { if ($file == 'description.txt') { // php less than or equal 5 $description = file_get_contents('./description.txt', FILE_USE_INCLUDE_PATH); } if ($file == 'subtitle.txt') { // php less than or equal 5 $subtitle = file_get_contents('./subtitle.txt', FILE_USE_INCLUDE_PATH); } if ($file == 'item.png') { $mainImage = 'item.png'; } if ($file == 'item.jpg') { $mainImage = 'item.jpg'; } } elseif (is_dir($file)) { $subFiles = scandir($file); foreach ($subFiles as $file2) { echo $file2; } } }
Problem is that $file2 is including the all of the files from the parent directory instead of just the items from the subfolder. If I echo out $files before the foreach it will also include the subfolder and subfolder files which isnt preferable but doesn't really get in the way of what I want to do either. Thanks