Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save name-k/cc9fb9ddf72eb743ed6a to your computer and use it in GitHub Desktop.
Save name-k/cc9fb9ddf72eb743ed6a to your computer and use it in GitHub Desktop.
php - Random file includ from path-to-folder
<?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