Skip to content

Instantly share code, notes, and snippets.

@illuzor
Last active September 3, 2018 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/c4b938c4af3f47416c1b6b890d1337d8 to your computer and use it in GitHub Desktop.
Save illuzor/c4b938c4af3f47416c1b6b890d1337d8 to your computer and use it in GitHub Desktop.
<?php
$folders = array_diff(scandir("images_previews", 1) , array('.',".."));
$result = [];
foreach($folders as $k => $v) {
$result[$k] = ["name" => $v, "preview" => random_file("images_previews/" . $v)];
}
function random_file($dir) {
$files = glob($dir . '/*.*');
$index = array_rand($files);
return $files[$index];
}
echo json_encode($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment