Author | Message |
---|
Meka][Meka Unstopable Posts: 700
| ok first create a file logo.php then paste the following:
Code: | <? $dh = opendir("."); while (false !== ($file = readdir($dh))) { if (preg_match('/\.gif$/i', $file) or preg_match('/\.jpg$/i', $file)) { $filelist[] = $file; } } srand((double)microtime()*1000000); $picnum = rand(0, sizeof($filelist) - 1); header("Location: " . $filelist[$picnum]); closedir($dh); ?> | put .gif and .jpg images into same dir as the logo.php now to get the callback for an image use the php file as an image source like so
Code: | <img src="logos/logo.php" border="0"> | -/Meka][Meka
|
Meka][Meka Unstopable Posts: 700
| here another way u can do it
Code: | <?php $total = "11"; // total number of images in the folder $file_type = ".jpg"; // type of files to use eg. .jpg or .gif $image_folder = "images/random"; /where images are $start = "1"; $random = mt_rand($start, $total); $image_name = $random . $file_type; echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />"; ?> |
|
Meka][Meka Unstopable Posts: 700
| an even better way todo it is like so
Code: | <?php $folder = ''; // Space seperated list of extensions, you probably won't have to change this. $exts = 'jpg jpeg png gif'; $files = array(); $i = -1; // Initialize some variables if ('' == $folder) $folder = './'; $handle = opendir($folder); $exts = explode(' ', $exts); while (false !== ($file = readdir($handle))) { foreach($exts as $ext) { // for each extension check the extension if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive $files[] = $file; // it's good ++$i; } } } closedir($handle); // We're not using it anymore mt_srand((double)microtime()*1000000); // seed for PHP < 4.2 $rand = mt_rand(0, $i); // $i was incremented as we went along header('Location: '.$folder.$files[$rand]); // Voila! ?> |
|