1. Put this in the htm file you cant to show the list of mp3 files it is in:
Invalid folder path.
'); } // Resolve the folder from the website root, regardless of where PHP is installed. $documentRoot = $_SERVER['DOCUMENT_ROOT'] ?? ''; $root = $documentRoot !== '' ? realpath($documentRoot) : false; if ($root === false) { http_response_code(500); exit('The website root could not be found.
'); } $rootPrefix = rtrim($root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $segments = array_values(array_filter(explode('/', $path), 'strlen')); $directory = realpath($rootPrefix . implode(DIRECTORY_SEPARATOR, $segments)); // Keep the scan inside the website root. if ( $directory === false || !is_dir($directory) || ($directory !== $root && strpos($directory, $rootPrefix) !== 0) ) { http_response_code(404); exit('The requested MP3 folder could not be found.
'); } $files = []; try { // Scan only the selected folder and include uppercase .MP3 extensions. foreach (new FilesystemIterator($directory) as $entry) { if (!$entry->isLink() && $entry->isFile() && strcasecmp($entry->getExtension(), 'mp3') === 0) { $files[] = $entry->getFilename(); } } } catch (RuntimeException $exception) { http_response_code(500); exit('The MP3 folder could not be read.
'); } if (!$files) { exit('No MP3 files found in this folder.
'); } // Sort Track 2 before Track 10. natcasesort($files); // Build links from the website root so they work from any HTML page. $folderUrl = $segments ? '/' . implode('/', array_map('rawurlencode', $segments)) . '/' : '/'; echo '