View Full Version : Rotate images using PHP

10-02-2008, 12:42 PM
Hi All,

Has anyone got a good script that will rotate images. I want to change the image on a page every few seconds or so and source the images randomly from a folder rather than being coded into the page like alot of JS solutions I have come across.

Thanks all. regards


10-02-2008, 01:14 PM
You'll need to use JS to rotate the images, as that part is happening client side (web browser).

As for random images from a directory again you can use JS to populate an array with the filenames and randomly select one after another.

So to answer your question you can achieve you aim with JS.

10-02-2008, 01:45 PM

its javascript

thats your champion

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function swap(){

var rand = Math.floor(Math.random()*11);
var path = ""; /// define path here and terminate with a forward slash ///
var ext = "jpg";

var image = path+"image"+rand+"."+ext;

document.getElementById('image').innerHTML = "<img src=\" "+image+ "\" /> ";

<body onload="swap()">

<div id="image"></div>


you need to set a path in the variable if needed

the image name needs to be...



where you have this line...

var rand = Math.floor(Math.random()*11);

by defining 11 gives you a range between 0 and 10. Change to suit.

where you have this div...

<div id="image"></div>

is where your random image will appear