I have one directory called images/tips.
Now in that directory I have many images which can change.
I want the PHP script to read the directory, to find the
Agreed with alexa. Use simple function.
function RandImg($dir) { $images = glob($dir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE); $randomImage = $images[array_rand($images)]; return $randomImage; } $the_image = RandImg('images/tips/'); echo $the_image;