Posted by john in javascript, php
A friend of mine recently requested a quick image rotator script that was not using Flash, but would use Javascript. Below is a script that will read through a single directory and look for any image file (jpg, gif, or png) and rotate it.
Requirements:
- PHP
- jQuery (latest version)
- InnerFade plugin (see docs for variables explanations and additional vars)
// Global Variables
$image_dir = "$_SERVER[DOCUMENT_ROOT]/examples/imgs"; // directory on server
$image_relative_path = '/examples/imgs'; // path to images relative to script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '4000'; // seconds each image will display (4000 = 4 seconds)
if($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$ext_bits = explode(".",$file); // finds file extensions
foreach($ext_bits as $key => $value){
if(in_array($value,$file_types)){
$image_rotation .= '
-
< ?= $image_rotation; ?>
Live demo or source file rotating three images for single directory
If you have any questions about this, please leave a comment.
John







January 11th, 2008 at 9:14 am
-
Hi,
Why not using $image_time in the Javascript part?
djot
-
[Reply]
john reply on April 4th, 2008:
Thanks for pointing that out. It’s all fixed now.
[Reply]