Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akmandev/7f5cbc0514621030f51ce7d901dc654f to your computer and use it in GitHub Desktop.
Save akmandev/7f5cbc0514621030f51ce7d901dc654f to your computer and use it in GitHub Desktop.
Fastest way to get random files from a directory (Recursively)
<?php
$directory = '/folder/name/etc';
$length = 100;
$command = 'find "' . $directory . '" -type f | shuf -n ' . $length . ';';
exec($command, $paths);
// $paths will contain every files with their paths as an array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment