Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
include 'rotate.php'; //also could use require
can I then do this?
CODE
<Body OnLoad="Rotate.php">
<?php
session_start();
initvars(); //create some variables if they don't exist
$imgdir = "path/to/image/directory"; //no trailing slash.
//grab all the images into an array
$dh = opendir($imgdir);
while (false !== ($image=readdir($dh))){
//test the image to make sure it is displayable and not recent
if ( $image !== "." &&
$image !== ".." &&
isImage($image) &&
!in_array($image, $_SESSION['oldimages']) &&
!in_array($image, $_SESSION['newimages'])){
$images[] = $image;
}
}
$num_images = count($images);
//grab a random image
$img = rand(0, $num_images-1);
serve($images[$img]);
function isFile($image){
global $imgdir;
if (!is_readable($imgdir.'/'.$image)) return false;
$parts = explode(".", $image);
$extension = $parts[count($parts)-1];
$permittedTypes = array("jpeg", "jpg", "png", "gif");
if (!in_array($extension, $permittedTypes)) return false;
return true;
}
function serve($image){
global $imgdir;
cleanSessions($image); //manipulate session data
@readfile($imgdir.'/'.$image); //deliver the file to the browser
exit(); //kill the script
}
function cleanSessions($image){
$_SESSION['newimages'][] = $image;
if (count($_SESSION['newimages'])){
$_SESSION['oldimages'] = $_SESSION['newimages'];
$_SESSION['newimages'] = array();
session_write_close();// this is important because we want the new data to be saved asap as there will be multiple calls on this file in short succession
}
}
function initvars(){
if(!isset($_SESSION['newimages'])) $_SESSION['newimages'] = array();
if(!isset($_SESSION['oldimages'])) $_SESSION['oldimages'] = array();
}
?>
var R = 0;
var intv = window.setInterval(setSrc, 35000);
function setSrc(){
var images = document.getElementsByName("rotator");
for (i=0; i<images.length; i++){
images[i].src = "rotate.php?id=" + R;
R++;
}
}
<img name="rotator" src="rotate.php" />
<!--include class, h and w and alt etc if you want -->
<?php
session_start();
initvars(); //create some variables if they don't exist
$imgdir = "path/to/image/directory"; //no trailing slash.
//grab all the images into an array
$dh = opendir($imgdir);
while (false !== ($image=readdir($dh))){
//test the image to make sure it is displayable and not recent
if ( $image !== "." &&
$image !== ".." &&
isImage($image) &&
!in_array($image, $_SESSION['oldimages']) {
$images[] = $image;
}
}
$num_images = count($images);
//grab 3 random images
while (count($_SESSION['newimages']) < 3) {
$img = rand(0, $num_images-1);
if (!in_array($images[$img], $_SESSION['newimages']){
$_SESSION['newimages'] = $images[$img];
}
}
serve();
function isFile($image){
global $imgdir;
if (!is_readable($imgdir.'/'.$image)) return false;
$parts = explode(".", $image);
$extension = $parts[count($parts)-1];
$permittedTypes = array("jpeg", "jpg", "png", "gif");
if (!in_array($extension, $permittedTypes)) return false;
return true;
}
function serve(){
global $imgdir;
cleanSessions(); //manipulate session data
$path = "[URL unfurl="true"]http://www.example.com/images/";[/URL]
foreach($_SESSION['newimages'] as $image){
$images[] = $path . $image;
}
echo json_encode($images); //output the array to the ajax object
exit(); //kill the script
}
function cleanSessions($image){
$_SESSION['oldimages'] = $_SESSION['newimages'];
$_SESSION['newimages'] = array();
session_write_close(); // this is important because we want the new data to be saved asap as there will be multiple calls on this file in short succession
}
}
function initvars(){
if(!isset($_SESSION['newimages'])) $_SESSION['newimages'] = array();
if(!isset($_SESSION['oldimages'])) $_SESSION['oldimages'] = array();
}
?>