| | |||||||
| |||||||
| |||||||
|
|
|
|
|
|
|
A PHP script that automatically rotates randomally selected banner images. By : thebomani <? /* ******************************* FreshSoftware Banner Image Rotater Version: 1.0 ******************************* ******************************* Intention ******************************* This script is a script desigend to display random banner images in jpg, gif and png formates. This script can also be modified to display any other file type by altering the $image_ext_array array bellow. Notice that the ARRAY_RAND function may choose the same file many times before selecting a different file. ******************************* System Requirments. ******************************* 1. PHP 4.2.0 or higher. 2. A Unix based Opertating System. 3. A Web Server (Apache Perphered). 4. Executable priviages on your server. Even in Safe Mode the PWD command is available provided that the executable directory has the same UID as this script. ******************************* Author. ******************************* This script was designed by Sulaiman Aleem of FreshSoftware.net. Send questions to webmaster@freshsoftware.net To watch this script in action visit http://www.freshsoftware.net/images/advertisments/freshsoftware/index.php ******************************* HOW TO INSTALL ******************************* 1) Copy this file to a directory that is accessbile by a HTTP server. 2) Copy banner images to the same directory containg this file. 3) Use the HEADER, ECHO or FPASSTHRU (recommended)function to display the banner image in a browser window. */ $dir = exec('pwd'); $open_dir = opendir("$dir"); //Add or remove files extensions to suit your needs. //Notice that the extensions are in upper and lower case. $image_ext_array = array( "jpg", "jpeg", "gif", "png", "JPG", "JPEG", "GIF", "PNG", ); $image_files = array(); if(!$open_dir){ die("can not $dir"); } else{ while(false !== ($file = readdir($open_dir))){ $ext = explode(".", "$file"); if(in_array($ext[1], $image_ext_array)){ $image = "$ext[0]" . "." . "$ext[1]"; array_push($image_files, $image); } } //If the PHP server is less that 4.2.0 the SRAND function is needed. //srand((float) microtime() * 10000000); $show_img = array_rand($image_files); //Optional: use the HEADER function to prevent the browser from caching the html content and image. //This is most use full when using the HEADER function to display the image //header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //header ("Cache-Control: no-cache, no-store, must-revalidate, private, max-age=0, proxy-revalidate, no-transform"); //header ("Pragma: no-cache"); //header("Vary: User-Agents"); //Edit the image ALT field to suit your needs. $image_alt = "FreshSoftware 1-866-343-3343"; $image_location = $dir . "/" . $image_files[$show_img]; $image_width = getimagesize($image_location); $image_height = getimagesize($image_location); //USE the ECHO function to display HTML Code. //echo "<img src=\"$image_files[$show_img]\" width=\"$image_width[0]\" height=\"$image_height[1]\" alt=\"$image_alt\">"; //The HEADER function often times fails to rotate an image when refreshing a browser. //header("location: http://freshsoftware-internal.net/images/advertisments/freshsoftware/$image_files[$show_img]"); //Recommended. These three lines make use of the FPASSTHRUE function. $open_image = fopen($image_location, 'rb'); fpassthru($open_image); fclose($open_image); closedir($open_dir); } ?>
More Link Farm Code Articles |
| |
| |