Skip to content

Instantly share code, notes, and snippets.

@illuzor illuzor/categories.php Secret
Last active Sep 3, 2018

Embed
What would you like to do?
<?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
You can’t perform that action at this time.