Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

View Poll Results: Has this helped you?

1. You may not vote on this poll
  • Yes

    1 100.00%
  • No

    0 0%
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Jun 2011
    Swindon, England
    Thanked 9 Times in 9 Posts

    Full Directory Image Pre-Loader (uses PHP aswell)


    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 
    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();
    // YOUR INPUT IS REQUIRED HERE... set the name of the folder (replace "<foldername>")
    define ('FOLDER','<foldername>');
    // 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
    // get array length
    var x = images.length;
    // loop through java array and load images.
    for(i=0; i<=x; i++)
    I found it useful.
    Last edited by LSCare; 06-28-2011 at 10:20 AM. Reason: addition to code.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts