<?php
function RandImg($dir)
{
$images = glob($dir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);

$randomImage = $images[array_rand($images)];
return $randomImage;
}

$the_image = RandImg('');
$the_image;
header('Content-Type: image/jpeg');
header("Location: $the_image");
?>