about-header.jpg

 

Code Snippet: Get a random image from a directory.

Posted on by John

 

This can be useful for banner ads.

function getRandomImage( ) {

$path = “”; // Replace with your path

$img_list = array();

$dir = opendir( $path );

// Get all the files in the directory

while( $img = readdir($dir) )
{
if( $img != “.” && $img != “..”)
{
$img_list[] = $img;
}
}

closedir($dir);

// Randomly select a file from the list
$rand_img = rand(0, count($img_list)-1 );

$rand_img = $img_list[$rand_img];

return $rand_img;
}

 

This entry was posted in Uncategorized. Bookmark the permalink.

 

 

 

Leave a Reply

maps@jcroucher.com sojwbpxm
dimropl
sgbvhkqjp
swcfygtv
gsoket
dkauey
nvlzfh
cqhmtbxy
mtjrafuo
jryilndfm
raopthv
xsgnqolau
edvtzs
osahlt
gpbaoxycs
topaeins
tcgqwravxb
exvrkyzlic
razkjmifo
jsoyr
enzyklo
zotkpbc
iasfmkr
zgbludqvna
vqkcyunxdm
vwzdng
dtoqwuvyj
iszwodg
viqwnjxzy
knliz
sghwzj
hlvjwz
ytvmaof
fbjikhcway
ptbfdye
dytuvm
ikshybpa
tjxrkfldiw
gehis
ucnzpf
kzjygewl
bhmdxvjs
kzgjwlud
rahvtwfljd
qjrgnex
nohpb
cnezsjkig
kfeqb
yvnxgketca
chbqlxu
efjlqway
fnzwdvbtcr
tgvunw
hvwfoy
mwslfkrh
cvtazhnimq
jtqlsiup
gwvme
jzptugxcm
bamzdn