This is one of the easiest ways to ad management out there. It selects a random file from the directory you chose and displays them randomly.
This code is useful if you have ad codes in different files and want to randomly rotate them.
- $rmdlist='';
- //$rmd_folder is the variable that choses the directory that the files will be in. Mine is images/rmd-img/
- // Make sure you DO NOT forget about the "/" at the end or this will not work.
- $rmd_folder = "images/rmd-img/";
- mt_srand((double)microtime()*1000);
- //use the directory class
- $imgs = dir($rmd_folder);
- //reads all the files from the directory you chose and ads them to a list.
- while ($file = $imgs->read()) {
- if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
- $rmdlist .= "$file ";
- } closedir($imgs->handle);
- //now, put all the images into a array
- $rmdlist = explode(" ", $rmdlist);
- $no = sizeof($rmdlist)-2;
- //now, generate a randon number from 0 - the number of images in the directory you chose.
- $random = mt_rand(0, $no);
- $image = $rmdlist[$random];
- //display's the image.
- echo '';
- ?>
|
No comments:
Post a Comment