Php supports multiple methods for randomly displaying images .? $ Handleopendir (.); current directory while (false! ($ Filereaddir ($ handle) {traverse the list ($ filesname, $ kzm) explode (., $ file) directory where the php Tutorial file is located; get the extension $ Handle = opendir ('./'); // Current Directory
While (false! ==( $ File = readdir ($ handle) {// traverse the directory where the php Tutorial file is located
List ($ filesname, $ kzm) = explode (".", $ file); // get the extension
If ($ kzm = "gif" or $ kzm = "jpg") {// file filtering
If (! Is_dir ('./'. $ file) {// folder filtering
$ Array [] = $ file; // Save the qualified file name to an array
}
}
}
$ Suiji = array_rand ($ array); // use the array_rand function to randomly extract a unit from the array.
?>
">
Instance 2
/*************************************** *******
* Filename: img. php
* Author: freemouse
* Web: www.zhutiai.com * mail: freemouse1981@gmail.com
* Date: 2010/12/27
* Usage:
*
*
**************************************** *******/
If ($ _ GET ['Folder']) {
$ Folder = $ _ GET ['Folder'];
} Else {
$ Folder = '/images /';
}
// The location where the image file is stored
$ Path = $ _ SERVER ['document _ root']. "/". $ folder;
$ Files = array ();
If ($ handle = opendir ("$ path ")){
While (false! ==( $ File = readdir ($ handle ))){
If ($ file! = "." & $ File! = ".."){
If (substr ($ file,-3) = 'GIF' | substr ($ file,-3) = 'jpg ') $ files [count ($ files)] = $ file;
}
}
}
Closedir ($ handle );
$ Random = rand (0, count ($ files)-1 );
If (substr ($ files [$ random],-3) = 'GIF') header ("Content-type: image/gif ");
Elseif (substr ($ files [$ random],-3) = 'jpg ') header ("Content-type: image/jpeg ");
Readfile ("$ path/$ files [$ random]");
?>
Readrand. php (this program actually generates a special webpage effect language)
$ Arrayall = file ("tp.txt" when reading the content of tp.txt to the array
$ Arrays = count ($ arrayall );
If ($ arrays = 1) {// because rand (0, 0) is wrong
$ Selectrand = 0;
} Else {
Srand (double) microtime () * 1000000); // sets the random seed.
$ Selectrand = rand (0, $ arrays-1 );
}
$ Exstr = explode (chr (9), $ arrayall [$ selectrand]); // randomly retrieve and divide all
?>
Document. write ('"target =" new ">" width = "200" height = "50" alt =" "> ');
HTML file