Created
March 22, 2018 00:00
-
-
Save thisbailiwick/3ad91431401279ca9fc8d7217ce3706d to your computer and use it in GitHub Desktop.
This will recursively list video files (currently filtered by a '.mp4' preg_match) links when put at the root of a url.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment