So I am trying to build a script that scans a directory and returns random images to be used as backgrounds.
The php looks like this:
$dir = \"views
Use glob() so you can filter the files.
glob()
$files = glob('views/img/bg/*.jpg'); $random = $files[array_rand($files)];
Since you're specifying *.jpg, $files contains only JPG files and you don't need to remove the . and .. items.
*.jpg
$files
.
..