...

View Full Version : Full Directory Image Pre-Loader (uses PHP aswell)



LSCare
06-27-2011, 05:51 PM
Hello,

I always found i wanted a pre-loader to load a whole directory of images (not really suitable for many images).

This was because if i added an image to a directory i didn't want to have to add that image to the pre-load script. This also removes the spelling errors that humans make in naming files.

EDIT LOG //

v1.1 - Error fix... The phpImage and javaImage variables were incorect and have now been fixed by removing the codetype prefix and un-capitalizing the initial I.

v1.2 - Addition of terms of use and instructions for use.

//

Here it is:



<script type="text/javascript">

/**

Full Directory Image Pre-Loader
v1.2

Deisgned by Laurence Care
This code is free to use for any purpose though please leave this notice in any copies taken.

This script will only work if used in a file with the extension .php

**/

// create counter
var i = 0;

// creat object
imageObj = new Image();

// build array of images
images = new Array();

<?php

// YOUR INPUT IS REQUIRED HERE... set the name of the folder (replace "<foldername>")
define ('FOLDER','<foldername>');
// END OF YOUR INPUT

// build array of files in folder
$image = glob(FOLDER . "/" . "*.*");

// create counter
$i = 0;

// loop through directory
foreach ($image as $value)
{
// create array for javascript loop
echo "images[" . $i . "] = '../" . $value . "';";

// next number in array
$i++;

}

?>

// get array length
var x = images.length;

// loop through java array and load images.
for(i=0; i<=x; i++)
{
imageObj.src=images[i];
}

</script>


I found it useful.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum