This will recursively list video files (currently filtered by a ‘.mp4’ preg_match) links when put at the root of a url.
Rough and not pretty but it’s functional.
<?php
function readDirs($path){
$dirHandle = opendir($path);
while($item = readdir($dirHandle)) {
$newPath = $path."/".$item;
if(is_dir($newPath) && $item != '.' && $item != '..') {
readDirs($newPath);
}
else{
if(preg_match('/\.mp4/', $newPath) === 1){
$relative_path = preg_replace('/' . preg_quote($_SERVER['DOCUMENT_ROOT'], '/') . '/', '', $newPath);
echo '<p><a href="' . $relative_path . '">' . $newPath . '</a></p>';
}
}
}
}
$path = __DIR__;
$original_path = $path;
echo "$path<br>";
readDirs($path);