Created
June 20, 2014 20:54
-
-
Save name-k/cc9fb9ddf72eb743ed6a to your computer and use it in GitHub Desktop.
php - Random file includ from path-to-folder
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 | |
$path = '/path/to/directory/'; // remeber trailing slash! | |
$handle = opendir ($path); | |
while (($filename = readdir ($handle)) !== false) | |
{ | |
if ($filename != '.' && $filename != '..') | |
{ | |
$file_array[] = $filename; | |
} | |
} | |
$rand = rand (0, count ($file_array)); | |
include ($path . $file_array[$rand]); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment