Jul 24, 2008

Extending The Image Preloader With Php4 - Dynamically adds your images to Preloader!

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Extending The Image Preloader With Php4 - Dynamically adds your images to Preloader!

SystemWisdom
Tutorial: Extending the Image Preloader with PHP4, by Rob J. Secord, B.Sc. (SystemWisdom)

Second Tutorial in a Series of 2 Tutorials! Be sure to have read the First One here: "Image Preloader With Progress Bar Status"


See a working Sample of this Script!
(Note: Preloads 100 images, some images are larger than others, and may take awhile for some people.)


Description:
A Tutorial for Extending the Image Preloader with PHP4 to Dynamically Populate the Array of Preloaded Images. This tutorial is the second in a series of 2 tutorials, and assumes that you have read the first tutorial: "Image Preloader With Progress Bar Status".


Intended Audience:
Beginner to Intermediate Web Developers.

Assumed knowledge:
-- Tutorial 1: "Image Preloader With Progress Bar Status"
-- Recursion Basics
-- Strings, Arrays, Loops
-- PHP4


Background:
In the last tutorial I wrote about building a Dynamic Real-Time Image Preloader with Progress Bar Status using only Client-Side code (namely JavaScript + HTML). The Preloader worked by creating an Array of Image URLs and passing that array into the Preloader class.

The problem is that you have to manually add your Image URLs to the Array, and everytime you add/remove an image, you would have to add/remove it from the Array also. Borrrrring..

In this tutorial, we are going to Extend the ImagePreloader with some Server-Side code (namely PHP4, but you could use any language you want, really). We will be altering the 'index.html' page; renaming it to 'index.php' and adding PHP4 code to search our Image Directory and dynamically build an array of all the Images for us!

Now you don't have to worry about editing the Preloader array at all! You could practically forget about it, once you have it installed!


Theory:
We will start by creating a single directory to hold all of our images on our web server. We will call this the Image-Root folder for the rest of this tutorial. Within this directory you may place all of your images and/or sub-folders with more images.

We will then use PHP4 to walk through all of the images in all of the sub-folders for us. You could easily extend this tutorial by restricting certian images/sub-folders from being preloaded, but I will leave that open for you, as that would depend on your images!

Within each folder (from the Image-Root folder), we will use PHP4 to check every entry in the folder (this could be an image, a sub-folder, any other file) and then determine what to do with each entry found.
If the entry is an image we will add its Path & Filename to our Array of images, which will serve as the Image URL to preload.
If it is a sub-folder we will recursively search that sub-folder in the exact same way.
Any other file(s) will be ignored, since they will not be preloaded.

Once we have completed searching the Image-Root directory for Images and building an Array of Image URLs, we will then output that Array into our Client-Side Preloader code. Since the Client-Side Preloader code also expects an array, we will have to build that array's code dynamically using simple Strings in PHP4. Then it is all ready to go!

Your server will then send the completed Preloader Code to the visitors browser, which will then begin preloading all of the Images for your site!

To demonstrate the simple recursion, I will be using the following sample directory structure for our example web-server:

-- index.php
-- ipreload.js
-- images
    [/tab]+--- sub_dir1
[tab]|    [/tab]|-------- Image1.gif
[tab]|    [/tab]|-------- Image2.gif
[tab]|
    [/tab]+--- sub_dir2
[tab]|    [/tab]|-------- Image3.gif
[tab]|    [/tab]|-------- Image4.gif
[tab]|
    [/tab]|--- Image5.gif
[tab]|--- Image6.gif
    |--- Image7.gif


The Bold entries are Folders, and the Italic entries are Files.
Now, imagine those are the real file and folder names, as I may use some of those names in examples for the rest of this tutorial.


Implementation:

I will start off, by showing you the completed Source Code to the Progress Bar page from our last tutorial (we will not be editing the 'ipreload.js' file in this tutorial at all, but you still need it as in the last tutorial!).

If you recall, our 'index.html' file looked like this:

File = index.html
CODE


<html>
<head>
<style type="text/css"><!--

.OuterBorder
{  border:1px solid #426394;
 padding: 2px 5px 2px 5px;
}
.FullDot
{  border:1px solid #426394;
 background-color:#DAE1EB;
 cursor:default;
}
.EmptyDot
{  border:1px solid #426394;
 background-color:#F3F6FA;
 cursor:default;
}
//--></style>

<script type="text/javascript" language="JavaScript" src="ipreload.js"></script>

<script type="text/javascript" language="JavaScript"><!--

var g_iStep = 0;

function OnImgUpdate( iProgress )
{
  if( (iProgress >= 1) && (iProgress <= 10) && (iProgress > g_iStep) )
  {
      g_iStep++;
      var oSpan = document.getElementById( "sDot" + iProgress + "" );
      oSpan.className = 'FullDot';
  }
}

function OnCompletion()
{
  document.location.replace('main.html');
}

function StartPreload()
{
  var szImages = new Array( "image1.gif", "image2.jpg", "image3.png", "etc..." );

  // Execute Image Preloader
  var oPreload = new ImagePreload( szImages, OnImgUpdate, OnCompletion );
}

--></script>

</head>
<body onload="StartPreload()">

<center>
<table cellpadding="0" cellspacing="0" border="0" class="OuterBorder">
<tr>
 <td>
    <span id="sDot1" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot2" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot3" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot4" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot5" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot6" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot7" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot8" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot9" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot10" class="EmptyDot">&nbsp;&nbsp;</span>
 </td>
</tr>
</table>
</center>

</body>
</html>


We will be adding only two sections to this code in this tutorial. But first, we must rename the file to 'index.php' without the single-quotes. Now you have a PHP file! Let's add some PHP4 Code to it.

We begin by adding a PHP code block to the very top of the page, where we will add the bulk of our code. I will first show you the completed code block and then I will explain how it works, this way you will have reference to what I am writing about. After I explain it, I will add it to the completed code from the first tutorial so you see how it fits in.

The PHP4 code block:
CODE

<?php

// Image-Root Directory..
$g_szImagesDir = 'images/';


// Global Variables used by 'BuildFileList' function...
$g_szFileList = array();
$g_iFileCount = 0;


// Build File List of Images
function BuildFileList( $szDir )
{   global $g_iDepth, $g_szFileList, $g_iFileCount;

   $oDirHandle = opendir( $szDir );
   while( false !== ($szFile = readdir( $oDirHandle )) )
   {
       if( $szFile == '.' || $szFile == '..' ) continue;

       $szCurrPath = $szDir.'/'.$szFile;
       if( is_dir( $szCurrPath ) )
       {
           BuildFileList( $szCurrPath );
       }else
       {
           if( (false !== strpos($szFile, '.jpg')) || (false !== strpos($szFile, '.gif')) || (false !== strpos($szFile, '.png')) )
           {
               $g_szFileList[$g_iFileCount++] = str_replace( './', '', $szCurrPath );
           }
       }
   }
   closedir( $oDirHandle );
   return;
}


// Start the search for Images!
BuildFileList( './' . $g_szImagesDir );


?>


The first thing you should note, are the 3 globally defined variables; g_szImagesDir, g_szFileList and g_iFileCount.

The first one 'g_szImagesDir' will be a string containing the path to and the name of the Image-Root folder. In our sample directory structure from above it would be: 'images/'. This variable will not be used by our 'BuildFileList' function, instead it will be passed into the function as the starting parameter.

The 'g_szFileList' variable is our Array which will hold all of our Image URLs to be preloaded.

And finally, the 'g_iFileCount' will count how many Images have been found and added to our 'g_szFileList' Array.

Next you will notice a PHP4 function called 'BuildFileList' which is the main focus of this tutorial. This function will recursively search our Image-Root directory and build a PHP4 Array of all of the Image URLs. Later on we will use the PHP4 Array to build our JavaScript Array for the visitor to download. The JavaScript Array will then be used on the visitors machine to Preload the images for your site!


Now, let's jump into the code for the 'BuildFileList' function.
The first thing you should notice about this function is that it accepts 1 parameter indicating the Directory (or Folder) to search in. To start off with, we would pass our Image-Root directory into this function, as you will see later. Knowing that, we can assume the starting value of the 'szDir' variable will be 'images/' and that's where the function will start searching for images.

The next line is an important one; it gives the function access to the globally defined variables that our function will require. These variables are not declared within the function because we want the values of those variables to maintain their state with each call to our function.

Now that our function is declared and has access to 2 of the previously defined global variables, we can start implementing the function itself. What is important to note before going any further, is that this function will be used "Recursively", meaning it will call itself. If you don't understand recursion I suggest you read up on the subject and come back to this tutorial once you have a good understanding of the concept. There are many good resources on the Internet to learn about recursion.

Now, the first thing we will need to do, is open a Directory Handle to the current folder (namely 'szDir' which at first will contain 'images/'). This is acheived with the built-in PHP4 function called 'opendir()'. We simply tell the PHP function what directory to open, and it will return a Directory Handle for us to use. When we are done using the Directory Handle we simpley call the built-in PHP function 'closedir()' to close it.

If you are having trouble following from the code above, we open the Directory Handle in this line of code:
CODE

$oDirHandle = opendir( $szDir );


Now that we have a Directory Handle, we can use that Directory Handle to read the entries found in the Directory using the built-in PHP function 'readdir()' which will return each directory entry with each successive call. What I mean is, every time we call the readdir() function it will return the next entry in the directory, until finally it returns False indicating that there are no more entries in the current directory.

So, if we look at the next line of code (starting with 'while') you'll notice we are using the 'readdir()' function which I just mentioned. First, we call the 'readdir()' function passing it the Directory Handle we created earlier. The 'readdir()' function then returns an entry in the directory which we store as 'szFile'. If this entry is Not Equal to Boolean False, then it is a valid entry, and the code continues inside of the 'while' loop. If however, the entry IS equal to Boolean False, then the 'while' loop quits, and the Directory Handle gets closed. The function then returns control to the calling statement.

Now, assuming the entry was valid (and from my sample directory structure given above it would be 'sub_dir1'), we would then check to see if the entry is equal to either "." or ".." which are Virtual Directories that point to the Current Directory and the Parent Directory respectively. If the entry is a Virtual Directory to either of the Current or Parent directories then we consider them invalid directories for our search, calling the 'continue' statement to search again.

The code for this looks like:
CODE

if( $szFile == '.' || $szFile == '..' ) continue;


If at this point, the directory entry is still valid, then it is either a sub-folder or a file. In either case, we append the entry name to the current directory name in proper format (resulting in either a sub-directory or a filename + path) as seen in the following code:
CODE

$szCurrPath = $szDir.'/'.$szFile;


Next we can determine whether the entry is really a sub-folder using the built-in PHP function 'is_dir()' which returns True if the entry is a Directory and False if the entry is not a Directory. If the entry IS a directory, then we simply call ourself through the method of recursion, which will go through the whole process again, but in the newly found sub-folder. This can be seen here:
CODE

   if( is_dir( $szCurrPath ) )
   {
       BuildFileList( $szCurrPath );  // <----  Recusive call..
   }else
   {
       // [...ignore for now...]
   }


As you can see, the 'BuildFileList' function is calling itself! But this time, it is passing a new directory (a sub-folder within the current directory) as the Directory to search from. When this happens, the script starts executing the whole function again, but with a new directory to search from. And when the function is done, it comes right back to this point in itself and continues executing the rest of the orignally called function.

However, if the entry we found is NOT a sub-folder then the 'is_dir()' function would have returned False and we would have entered the 'else' block of the if statement, which looks like:
CODE

   if( is_dir( $szCurrPath ) )
   {
       // [...ignore for now...]
   }else
   {
       if( (false !== strpos($szFile, '.jpg')) || (false !== strpos($szFile, '.gif')) || (false !== strpos($szFile, '.png')) )
       {
           $g_szFileList[$g_iFileCount++] = str_replace( './', '', $szCurrPath );
       }
   }


At this point, we know that the entry we found is not a Virtual Directory or even a Physical Directory, so we proceed to assume it is a valid file. But we don't know what type of file it is, and so we check the File Extension to determine if the file is an Image File used on websites.
Since the 'szFile' variable is a string containing the entry name, we can search that string using PHP4 to find and compare the file extension. We use the built-in PHP function 'strpos()' to server this purpose.
We tell the 'strpos()' function what string to search, and what string to search for (in this case, a file extension), and if the function returns Boolean False then the file extension we searched for was not found. Otherwise, the 'strpos()' function will return spot (or starting index) that the extension was found in the search string. The fact that it doesn't return False is enough for us to proceed.

For example, we are searching the 'szFile' string for the File Extension '.jpg' and if the result is Not Equal to Boolean False then the File Entry is a Jpg Image File:
CODE

       if( false !== strpos($szFile, '.jpg') )
       {
           // [...ignore for now...]
       }


Hence, if the File Entry is a valid Image File (.jpg, .gif or .png), then the full path and filename are added to our Image URL Array ('g_szFileList') which we created globally. We also increment (add 1 to) our 'g_iFileCount' variable, to keep track of how many Image URLs we have.
A good point to note is the removal of any unneccessary Virtual Current directory entries that may have been added to the file path using, before adding the Image URL to the Array. Our end result for the File Extension Test:
CODE

       if( (false !== strpos($szFile, '.jpg')) || (false !== strpos($szFile, '.gif')) || (false !== strpos($szFile, '.png')) )
       {
           $g_szFileList[$g_iFileCount++] = str_replace( './', '', $szCurrPath );
       }



And finally, once the function is ready to exit, the 'closedir()' function is called to clean up our Directory Handle that we used, as in:
CODE

closedir( $oDirHandle );



And that concludes the 'BuildFileList' function. To recall; We pass in the Image-Root directory to search and the function recursively searches all sub-directories building an Array of valid Image File entries found.


Now that we have our Global Variables and our Function declared, we can call the function passing in our Image-Root directory, and when the function is done we will have an Array of Image URLs, which is done in one line of code:
CODE

BuildFileList( './' . $g_szImagesDir );

The './' denotes that the Image-Root directory resides in the Current Directory from which this script is executed.


Now that we have completed the first section of this tutorial, I will show you a sample of the 'index.php' up to this point so far. We will use this as reference for the last part of the tutorial, which fortunately is alot shorter!

File = index.php
CODE

<?php

// Image-Root Directory..
$g_szImagesDir = 'images/';


// Global Variables used by 'BuildFileList' function...
$g_szFileList = array();
$g_iFileCount = 0;


// Build File List of Images
function BuildFileList( $szDir )
{   global $g_iDepth, $g_szFileList, $g_iFileCount;

   $oDirHandle = opendir( $szDir );
   while( false !== ($szFile = readdir( $oDirHandle )) )
   {
       if( $szFile == '.' || $szFile == '..' ) continue;

       $szCurrPath = $szDir.'/'.$szFile;
       if( is_dir( $szCurrPath ) )
       {
           BuildFileList( $szCurrPath );
       }else
       {
           if( (false !== strpos($szFile, '.jpg')) || (false !== strpos($szFile, '.gif')) || (false !== strpos($szFile, '.png')) )
           {
               $g_szFileList[$g_iFileCount++] = str_replace( './', '', $szCurrPath );
           }
       }
   }
   closedir( $oDirHandle );
   return;
}


// Start the search for Images!
BuildFileList( './' . $g_szImagesDir );


?>

<html>
<head>
<style type="text/css"><!--

.OuterBorder
{  border:1px solid #426394;
 padding: 2px 5px 2px 5px;
}
.FullDot
{  border:1px solid #426394;
 background-color:#DAE1EB;
 cursor:default;
}
.EmptyDot
{  border:1px solid #426394;
 background-color:#F3F6FA;
 cursor:default;
}
//--></style>

<script type="text/javascript" language="JavaScript" src="ipreload.js"></script>

<script type="text/javascript" language="JavaScript"><!--

var g_iStep = 0;

function OnImgUpdate( iProgress )
{
  if( (iProgress >= 1) && (iProgress <= 10) && (iProgress > g_iStep) )
  {
      g_iStep++;
      var oSpan = document.getElementById( "sDot" + iProgress + "" );
      oSpan.className = 'FullDot';
  }
}

function OnCompletion()
{
  document.location.replace('main.html');
}

function StartPreload()
{
  var szImages = new Array( "image1.gif", "image2.jpg", "image3.png", "etc..." );

  // Execute Image Preloader
  var oPreload = new ImagePreload( szImages, OnImgUpdate, OnCompletion );
}

--></script>

</head>
<body onload="StartPreload()">

<center>
<table cellpadding="0" cellspacing="0" border="0" class="OuterBorder">
<tr>
 <td>
    <span id="sDot1" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot2" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot3" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot4" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot5" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot6" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot7" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot8" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot9" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot10" class="EmptyDot">&nbsp;&nbsp;</span>
 </td>
</tr>
</table>
</center>

</body>
</html>



Now, you should be able to notice that the new code block we have just added doesn't interact with the old page from the previous tutorial in any way! Not yet, at least.
We will now use our PHP Array of Image URLs to populate the JavaScript Array of Image URLs, completing the Dynamic Image Preloader with Progress Bar Status!

We start, by adding another PHP code block to our 'index.php' page, but not at the top like before, rather, in the middle of our JavaScript Array!
Since PHP outputs text to the source code of your HTML file, we will output our Array as text into our JavaScript source code for the visitor to download.

We will start this last section by looking at the completed code block all alone so that you may reference it as I go along:
CODE

<?php
       for( $i = 0; $i < $g_iFileCount; $i++ )
       {
           if( $i == ($g_iFileCount - 1) )
               echo '"' . $g_szFileList[$i] . '"';
           else
               echo '"' . $g_szFileList[$i] . '",';
       }
?>


You will notice it is a simple FOR Loop that iterates through all of the Image URLs in the PHP Array 'g_szFileList'. It is for this purpose that we kept track of how many Images we had in the Array using the global variable 'g_iFileCount'.

Now before we look at how this is implemented, it is good to understand what we are trying to output, which is basically a series of comma-seperated quoted strings, as in:

"sting1", "string2", string3", "etc"

Of course, the strings themselves are the Image URLs, so all we have to do issurround each Image URL in Quotes ("...") and seperate them with commas! So for each iteration of the FOR loop, we could just output either: A quoted string + a comma; OR: A comma + a quoted string.

Now, if you choose to output A quoted string + a comma, then the very lasted quoted string should NOT have a comma following it, right? (look at example just above..).

But, if you choose to output A comma + a quoted string, then the very first quoted string shouldn't have a comma in front of it, right? (again, look at example just above..).

So, we will choose (for this tutorial) to output: A quoted string + a comma, during each iteration. Which means (as previously stated) that we must take care NOT to output a comma after the very last quoted string. We achieve this with a simple IF statement that checks whether the current Array Index is Equal to the Total Number of Image URLs in our Array (which is stored in the 'g_iFileCount' variable. But don't forget, Arrays are indexed starting from 0 not 1, so we must minus 1 from the 'g_iFileCount' variable when comparing, as in:
CODE

   if( $i == ($g_iFileCount - 1) )


This checks to see if the current Array Index is equal to the Total Number of Image Files minus 1. If so, then we just output the quoted string, otherwise we output the quoted string + a comma, as in:
CODE

       for( $i = 0; $i < $g_iFileCount; $i++ )
       {
           if( $i == ($g_iFileCount - 1) )
               echo '"' . $g_szFileList[$i] . '"';
           else
               echo '"' . $g_szFileList[$i] . '",';
       }


You may have to look carefully at the quotes in the above example; the single quotes are PHP and the double-quotes are the output.

Now that we know what we are outputting and how we are outputting it, we can place this PHP code block in the correct spot in our 'index.php' page. Looking at the examples provided above, I am sure you could figure out where that spot would be, but in either case, I shall show you:
CODE

function StartPreload()
{
  var szImages = new Array( <?php
       for( $i = 0; $i < $g_iFileCount; $i++ )
       {
           if( $i == ($g_iFileCount - 1) )
               echo '"' . $g_szFileList[$i] . '"';
           else
               echo '"' . $g_szFileList[$i] . '",';
       } ?> );

  // Execute Image Preloader
  var oPreload = new ImagePreload( szImages, OnImgUpdate, OnCompletion );
}


Notice it is placed directly inside of the 'Array()' function as its parameters, thus creating the required JavaScript Array used to Preload the images on the visitors machine!


Putting it all together, we have:


File = index.php
CODE

<?php

// Image-Root Directory..
$g_szImagesDir = 'images/';


// Global Variables used by 'BuildFileList' function...
$g_szFileList = array();
$g_iFileCount = 0;


// Build File List of Images
function BuildFileList( $szDir )
{   global $g_iDepth, $g_szFileList, $g_iFileCount;

   $oDirHandle = opendir( $szDir );
   while( false !== ($szFile = readdir( $oDirHandle )) )
   {
       if( $szFile == '.' || $szFile == '..' ) continue;

       $szCurrPath = $szDir.'/'.$szFile;
       if( is_dir( $szCurrPath ) )
       {
           BuildFileList( $szCurrPath );
       }else
       {
           if( (false !== strpos($szFile, '.jpg')) || (false !== strpos($szFile, '.gif')) || (false !== strpos($szFile, '.png')) )
           {
               $g_szFileList[$g_iFileCount++] = str_replace( './', '', $szCurrPath );
           }
       }
   }
   closedir( $oDirHandle );
   return;
}


// Start the search for Images!
BuildFileList( './' . $g_szImagesDir );


?>

<html>
<head>
<style type="text/css"><!--

.OuterBorder
{  border:1px solid #426394;
 padding: 2px 5px 2px 5px;
}
.FullDot
{  border:1px solid #426394;
 background-color:#DAE1EB;
 cursor:default;
}
.EmptyDot
{  border:1px solid #426394;
 background-color:#F3F6FA;
 cursor:default;
}
//--></style>

<script type="text/javascript" language="JavaScript" src="ipreload.js"></script>

<script type="text/javascript" language="JavaScript"><!--

var g_iStep = 0;

function OnImgUpdate( iProgress )
{
  if( (iProgress >= 1) && (iProgress <= 10) && (iProgress > g_iStep) )
  {
      g_iStep++;
      var oSpan = document.getElementById( "sDot" + iProgress + "" );
      oSpan.className = 'FullDot';
  }
}

function OnCompletion()
{
  document.location.replace('main.html');
}

function StartPreload()
{
  var szImages = new Array( <?php
       for( $i = 0; $i < $g_iFileCount; $i++ )
       {
           if( $i == ($g_iFileCount - 1) )
               echo '"' . $g_szFileList[$i] . '"';
           else
               echo '"' . $g_szFileList[$i] . '",';
       } ?> );

  // Execute Image Preloader
  var oPreload = new ImagePreload( szImages, OnImgUpdate, OnCompletion );
}

--></script>

</head>
<body onload="StartPreload()">

<center>
<table cellpadding="0" cellspacing="0" border="0" class="OuterBorder">
<tr>
 <td>
    <span id="sDot1" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot2" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot3" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot4" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot5" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot6" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot7" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot8" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot9" class="EmptyDot">&nbsp;&nbsp;</span>&nbsp;
    <span id="sDot10" class="EmptyDot">&nbsp;&nbsp;</span>
 </td>
</tr>
</table>
</center>

</body>
</html>




Conclusion:

Well, I hope that you have learned something from this tutorial, and maybe even use such a preloader in your web sites!

Please feel free to comment on this tutorial, if you noticed anything wrong or out of place in this tutorial, please don't hesitate to mention it!
I am interested in all feedback really, I'm curious about what you think of my writing, tutorial, methods used, code, etc.. Thanks!


See a working Sample of this Script!

biggrin.gif

 

 

 


Reply

snlildude87
Wow, the sample took a long time to load!

As always, awesome tutorial! I don't have the opportunity to try it out yet, but I will on the weekends.

I think it'll be cool if you show the images that were preloaded instead of displaying the messages...

Reply

SystemWisdom
Yeah, the images take a while to load because there are so many, roughly 100 Images that are preloaded in the sample.

But the only reason I didn't show the images afterward is because the images are actually the GUI to my site, and once I get my site online again you will see all of the images in place on my site, instead of the plain text page I have at the end of it now.

Sorry 'bout that, I should have my site online soon, and then these links will automatically point o the right preloader and you will see my site!!

I hope you enjoy the tutorials when you find the time to read and test them out!

Reply

whyme
excellent PHP tutorial, keep up the good work. smile.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : extending, image, preloader, php4, dynamically, adds, images, preloader

  1. Image Hosting Link On My Website?
    need help (2)
  2. Images For Website
    (0)
    Which is the best site to build our images to host on the home pages....
  3. Trap17 Dynamic Recent Post/topic Image
    (17)
    Some may remember a while back I created a dynamic image that would tell you your post count and
    last active for trap. It had a bit of a run but then died off. It just wasn't very useful.
    BUT NOW I am presenting the most epic trap17 image Ever. This one is SUPER customizable and already
    works for ALL MEMBERS ! It is designed to be put in your sig so other members can see the
    recent topics you have written. It is still in early early beta stage but soon it will have the
    date posted along with some other cool features. So I'm sure you are all excited t....
  4. Exact Image Index
    (2)
    i had this idea a while back but i guess the genious at google are a couple steps ahead again, but
    it's the idea is instead of relying on the tags of an image when searching it actualy reads
    what's realy in that image. this can be a great step ahead witch can eliminate some mistakes
    that happen when searching images. i like it /smile.gif" style="vertical-align:middle" emoid=":)"
    border="0" alt="smile.gif" />. CHECK IT:
    http://www.bigblueball.com/forums/general-...html#post229009 ....
  5. How To Add Images
    (9)
    Well i just got my site hosted and i wasable to add my stuf to the ind manager, but the site didnt
    work without the images and i coudlnt find out how to add images....
  6. Link Image Css Bug In Firefox
    Can anyone help me? (7)
    I have a problem in a site I am creating. I have styled my post content links in the following
    way. CODE #post-content a {     background-color: #bf6f3c;     color: #fff;
        padding: 2px 2px 1px 2px;     border-bottom: 1px solid #7f4926; } #post-content
    a:hover {     color: #f5fac7; } And when I insert an link image like so: There
    seems to be an extra border inherited from my #post-content a style. I have attached the screenshot
    to show the problem. This was how my link image should look like: CODE #post-content a img { ....
  7. Image Upload
    ?!? (11)
    I need the image upload script which automatically resized the image by specified size and store it
    in the specified folder.....
  8. Image Viewing
    (3)
    IrfanView If you are looking for something better than the softwares for image viewing included in
    windows, you can try these incredible program, really small, really fast, and simple to learn you
    can basic edit your photos with IrfanView, and its free /biggrin.gif" style="vertical-align:middle"
    emoid=":D" border="0" alt="biggrin.gif" /> here, a link to download, this is the version i use i
    have no problems with this one: http://rapidshare.com/files/106016448/iview397.rar ....
  9. How To Display Images Of A Directory
    (4)
    I am trying to do a simple thing. I want to display all the images of a directory on a single page
    with the checkbox next to each image, so that i can select multi images and i can delete selected
    images. Following few lines of code display the images of a directory.. i need help to put the
    check boxes with each image. and I dont understand how can i select multi images with check box and
    then delete them. I hope someone can help. thanks. CODE <?php $path = "./";
    $dir_handle = @opendir($path) or die("Unable to open folde....
  10. The Right Web Album/image/photo Album Host?
    a question regarding the confusion of choosing the right host (9)
    Hello, since I can't post to the Internet secion of this forum, I'll post it here. I am
    still doing my best to get more than 30 credits, right now I only have the half Anyway alot of our
    relative uses Flickr (which sucks--limitations) and Kodak photo sharing thingy. Now, me I wanted to
    be unique at the same time to help other relatives in choosing the right site to upload their
    pictures of course, with a wonderful features. Can you please help me or recommend me some photo
    sharing sites, where I can upload my pictures or pictures of our family? If possible, th....
  11. Imagefilez.com Now Hosts - More Than 1 Million Images - Lots More To Come
    (5)
    Hi Guys, I am really proud & happy at the same time to announce to you all that Imageflez is now
    hosting more than 100,000 images. We really had a tough time recently cleaning spam on the server,
    then came the big server upgrade, then bot attacks.. it was really tough times, But finally we are
    now as strong as we were ever before. So spread the word and use Imagefilez & now let's grow.
    /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> Admin -
    Imagefilez.com....
  12. Background Image Swap Script
    Change a Background Image based on clock time (15)
    Background Image Changer Script To swap the background image from your CSS file according to the
    Server Clock Time. 1.) In your CSS file, add the following rule: CODE body {
        background: url(time.png); } 2.) Create a "folder" named time.png. 3.) Into the
    folder, place three images named morning.png, day.png, night.png. 4.) Also, in the same folder,
    create an index.php file and copy/paste the following script. CODE <?php $hour =
    date('H'); if ($hour < 12 ) {     $image =
    "morning.png"; } ....
  13. Do You Use Imagefilez.com?
    ImageFilez.com : Free Image and Video Hosting (30)
    Do you use ImageFilez.com? If so, for what and how long? If not, why? /huh.gif"
    style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /> Please vote and reply to
    this thread with your responses. I don't personally, because I have an account on Photobucket
    and ImageShack, and I sometimes use the Free Hosting that comes embedded into my forum and at the
    site I moderate.....
  14. Google Rolling Image Trick
    (11)
    You might already know this but it doesn't really matter.... OK this isnt a useful trick or
    something, its just something thats fun to see. 1. Goto Google 2. Click "images" 3. Type "jesus"
    or any other word 4. You will get a page which is full of images 5. Then delete the item from the
    address bar and paste the below script: CODE java script:R=0; x1=.1; y1=.05; x2=.25; y2=.24;
    x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function
    A(){for(i=0; i<DIL; i++){DIS=DI[ i ].style; DIS.position=&#....
  15. Image Not Taking The Right Size In Web Page
    An image is correct when designed, but not when put in a website (1)
    When trying to make a web page with a GIF image on it which runs a coloured bar along the top and a
    coloured curve along the side, I come across the weird thing that, when I put the image on a web
    site, it does not take in the whole top and does not run from top to bottom completely. The image is
    made in Adobe Photoshop at a resolution of 1024X768 pixela and looks correct , ie. the horizontal
    bit runs completely from left to righ and the vertical bit completely from topright to bottom right,
    yet when put in to the web page, it shows with big margins left and right and to....
  16. Adding Shine To Text
    images say "Tiger Ads", but, the board is clsed, so, i'm r (1)
    OK, in this tut, I am going to show you how to add shine to any text. For this example I will be
    using the TigerAds affiliate button. (the board is since closed so, I'm not really advertising
    /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" />) OK then,
    lets get started! 1. Open up the image that you will be using, this is mine: 2.
    Now that your image is open and making sure that its the .psd so you can edit the text on it. In
    your layers menu, hold down CTRL and click on the text layer so that only the te....
  17. Getting Flash Images On A Site
    (1)
    well, i don' t have a site yet, but about 6 months ago i made a template, with flash buttons and
    all, with sound and everything i was so proud so i tryed to put em on there with a special code u
    needet or something ,so i did, but i got blank images,, i even tryed uploading it on the site it
    didn't work, so i asked around they said u can' t install them on a cpanel, u need ftp, so i
    downloadet the program needet and i got stuck there, so basicly how do u do that,and could some1
    help me out how to get it working on a cpanel....
  18. A Simple Php Captcha - Image Validation
    (21)
    OK, I recently had the need to create a PHP CAPTCHA system for a friend, and I am sharing this as a
    tutorial with the good people here at Trap17. I am sure you have all seen a CAPTCHA before (although
    you may not have known what it was called). They are the little codes you often have to enter when
    you register with a site, to make sure you are a person and not an automated script. Some common
    examples look something like this: My system doesn't really do anything as fancy, but I
    think that it is slightly more readable that some of those that get generated. Every....
  19. Mylot.com
    earn a lot of money on discussion and upload image (16)
    The site is mylot and all you have to do is stay active in the site by creating or responding to
    discussions and upload photos. You get 1 cents minimum for each response you post or when someone
    responds to your topic. Your rating in the site goes up by 1 for each unique discussion you take
    part in or when someone responds to the discussions started by you for the first time. They pay you
    based on the quality of the posts you make. so, if you really make a worthy reply, you can expect
    5-10 cents for a reply. Respond to as many discussions as possible and earn. You ca....
  20. Scrolling Images?
    How to Make an Image Scroll With the Page (5)
    I'm trying to make my homepage look a little fancier and I've got a nice background image,
    but I want it to scroll with my page, like if you scroll down the image will still appear like it
    does on the top of the page. Can someone tell me how to do this? I'm using Microsoft Frontpage
    to edit it. I'm not sure what programming language this would be, probably CSS or Javascript,
    but I can edit the page script with Notepad or something to make this work. Right now the page is
    purely HTML, so whichever language this is, can somebody also give me the tags and ma....
  21. How To Create Embed Image Mail In Gmail
    (48)
    Hi to all ! Anybody can help me to create an email with embedded image so that mail reader
    automatically see that image. Moreover I wont attached that image as it appears small in size in on
    gmail. Thanks in Advance. ....
  22. Watermark Your Image With Simple Php Script
    found it on the net (34)
    This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
    Scripts site. Just in case the site may not show, I will include the code here: List of things
    needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
    script below with name (i.e. watermark.php) CODE <?php // this script creates a watermarked
    image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly
    transparent gif image with the watermark - goes in the same directory as this script // ....
  23. Expanding Image Gallery
    Images Expanding on a mousover (6)
    I was looking through wired today, and i noticed :
    http://www.hotwired.com/webmonkey/06/08/index2a.html looks like a pretty nifty image gallery
    effect, though i noticed that it wont display properly in FireFox. Does anyone have any links or
    examples of other image gallery code, i find it pretty fascinating.....
  24. Can You Add Images Into A Mysql Database?
    Using Php? (20)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  25. What Is Theme Of Your Current Desktop Image
    about images, pictures... (19)
    My current desktop image is standard windowsXP Home image. /tongue.gif' border='0'
    style='vertical-align:middle' alt='tongue.gif' /> And U? ....
  26. Making A Scroll Bar In Flash
    with an image and words on it (4)
    does anybody know how to make a scrollbar for my game page I am making on my site. This whole site
    is completely in flash. I know how to make a scrollbar for just words but not when there is an
    image on there also. Does anybody know?....
  27. Creating Links In Images
    Using ImageReady (17)
    In this tutorial I will show you how to create links in your image. I'm shore there's a lot
    of different ways you can do this, but I'll just show you how to do it real easy. 1) After
    creating the image you want to add links to in photoshop, make shore the mode is set to RGB Color.
    Just go to Image -> Mode -> RGB Color. 2) Go to File -> Jump To -> Adobe ImageReady. Your image
    will now load into ImageReady. For this tutorial I will be using this image that I found: I will
    make the buttons of this navigation bar into links. 3) Press K to select the slice t....
  28. Blank Images - (white Square W/red X)
    FTP uploaded images don't display (8)
    Hey Guys, PROBLEM: Uploaded website & all images display as blank white box with red X on the
    webpages. Tech Info: Am using domain hosting (not subdomain hosting) All my html pages are in
    folder "public_html". All my images are present in folder named "userfiles". Both folders are "root"
    on the server in my cpanel (ie. not in subfolders). The html code on my webpages "pointing"
    (incorrectly???) to the images is: QUESTION: 1) Whats up??? 2) Is this html 3) Does the Xisto
    server require that images only be placed in a specific folder OR subfolder in order to display....
  29. Turning An Image Into A Cartoon Style - Photoshop
    Tutorial on cartooning images. (30)
    This tut will show you how to make a photo look cartoonish in three easy steps... 1)Open your
    image in photoshop, doesnt really mater what size or shape anything really a landscape, city, or a
    person. I am using a picture of a football player in this example 2)Go up to
    Filter>Blur>Gaussian Blur and set the radius at 3.0 or higher depending on the effect your looking
    for. 3)Last go Edit>Fade Gaussian Blur. A window will pop up... set the mode to darken for tha
    cartoonish effect or to any other mode for plenty of other effects. Lower the opacity if you
    don't....
  30. Exporting Transparent Images In Photoshop To Flash
    Needed: Photoshop 7 or CS, Flash MX (4)
    First of all, it is important that you make sure the image you wish to export is on a transparent
    layer. The transparent layer is a checkered background in photoshop. You can see this checkered
    background in the image to the left. In this example, I created a quick glass icon which has
    different levels of transparency. This is the image I will be exporting, whilst preserving
    it's transparency. Once your image is on a transparent background, head to file > save for
    web. You can only export complex transparency using the .png filetype. So from the drop down....

    1. Looking for extending, image, preloader, php4, dynamically, adds, images, preloader

Searching Video's for extending, image, preloader, php4, dynamically, adds, images, preloader
Similar
Image
Hosting Link
On My
Website? -
need help
Images For
Website
Trap17
Dynamic
Recent
Post/topic
Image
Exact Image
Index
How To Add
Images
Link Image
Css Bug In
Firefox -
Can anyone
help me?
Image Upload
- ?!?
Image
Viewing
How To
Display
Images Of A
Directory
The Right
Web
Album/image/
photo Album
Host? - a
question
regarding
the
confusion of
choosing the
right host
Imagefilez.c
om Now Hosts
- More Than
1 Million
Images -
Lots More To
Come
Background
Image Swap
Script -
Change a
Background
Image based
on clock
time
Do You Use
Imagefilez.c
om? -
ImageFilez.c
om : Free
Image and
Video
Hosting
Google
Rolling
Image Trick
Image Not
Taking The
Right Size
In Web Page
- An image
is correct
when
designed,
but not when
put in a
website
Adding Shine
To Text -
images say
"Tiger
Ads",
but, the
board is
clsed, so,
i'm r
Getting
Flash Images
On A Site
A Simple Php
Captcha -
Image
Validation
Mylot.com -
earn a lot
of money on
discussion
and upload
image
Scrolling
Images? -
How to Make
an Image
Scroll With
the Page
How To
Create Embed
Image Mail
In Gmail
Watermark
Your Image
With Simple
Php Script -
found it on
the net
Expanding
Image
Gallery -
Images
Expanding on
a mousover
Can You Add
Images Into
A Mysql
Database? -
Using Php?
What Is
Theme Of
Your Current
Desktop
Image -
about
images,
pictures...
Making A
Scroll Bar
In Flash -
with an
image and
words on it
Creating
Links In
Images -
Using
ImageReady
Blank Images
- (white
Square W/red
X) - FTP
uploaded
images
don't
display
Turning An
Image Into A
Cartoon
Style -
Photoshop -
Tutorial on
cartooning
images.
Exporting
Transparent
Images In
Photoshop To
Flash -
Needed:
Photoshop 7
or CS, Flash
MX
advertisement



Extending The Image Preloader With Php4 - Dynamically adds your images to Preloader!



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE