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; } } }
Проблема в том, что $file2 включает все файлы из родительского каталога, а не только элементы из подпапки. Если я повторю $files перед foreach, он также будет включать файлы подпапок и подпапок, что не является предпочтительным, но на самом деле не мешает тому, что я хочу сделать. Спасибо