PHP Conference Kansai 2025

Voting

: eight minus five?
(Example: nine)

The Note You're Voting On

hanan dot ali dot shaikh at gmail dot com
16 years ago
This function is used to display random image i.e. at header position of a site. It reads the whole directory and then randomly print the image. I think it may be useful for someone.

<?php
if ($handle = opendir('images/')) {
$dir_array = array();
while (
false !== ($file = readdir($handle))) {
if(
$file!="." && $file!=".."){
$dir_array[] = $file;
}
}
echo
$dir_array[rand(0,count($dir_array)-1)];
closedir($handle);
}
?>

<< Back to user notes page

To Top