PHP script random images From a folder | prosoxi.com

Categorized | PHP

PHP script random images From a folder

Add a php file with filename imageheader.php

<?php
Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
Header("Pragma: no-cache");
Header("Content-Type: image/jpg");
//Header("Content-Type: image/gif");
 
$dir = "images/randomimages"; // This is the folder where the images are
srand((double)microtime()*1000000);
 
$i = 0;
 
$dirHandle = opendir($dir); // Open the images folder
while(($im = readdir($dirHandle)))
 
{
if($im != ".." &amp;&amp; $im != ".") // Don't read in the 2 folders ".." and "."
{
$image[$i] = $im; // Select an image
$i++;
}
}
closedir($dirHandle); // Close the folder
$n = rand(0,(count($image)-1));
if(!readfile($dir."/".$image[$n])) // Read the image
readfile($dir."images/errorimage.jpg"); // If the script can't find the directory, display this image
?>

And Final
<div id=”main_header” style=”background-image:url(imagesheader.php);”></div>



Leave a Reply

Domain Finder

Domain Finder Tool by Truste.gr

read more for domains

Advertisers

Wedstar all about wedding - gamos - γαμος
Κατασκευή ιστοσελίδων
Domain Names | Hosting

Adds