certainlyakey
6/23/2014 - 1:29 PM

Pick random file from directory with given extensions

Pick random file from directory with given extensions

<?php 
//http://stackoverflow.com/questions/4478783/select-random-file-from-directory
function random_video($dirName = "files/videos/")
{
    $files = array_merge(glob($dirName . "*.m4v"), glob($dirName . "*.mp4"), glob($dirName . "*.mov"));
    $file = array_rand($files);
    return $files[$file];
}
?>
<a href="<?php echo random_video(); ?>">Video</a>