You are here

22 November 2016

Select a random file from directory. This can be useful if you want to display a random image on your website. For an example a background image randomly from a directory in your files.

Source code viewer
  1. $files = glob(realpath('../img') . '/*.*');
  2. $file = array_rand($files);
  3. echo $files[$file];
Programming Language: PHP