Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post preload image in $file ?!?!?!

    Good day to you all,
    Is it possible and how can I generate from a variable (which is reading trough a directory to find images) to get those images upload before the page load ?

    Let say I'm using that javascript to preload image :

    PHP Code:

      
    <SCRIPT language="JavaScript">
        <!--

        if (
    document.images)
        {
          
    preload_image_object = new Image();
          
    // set image url
          
    image_url = new Array();
          
    image_url[0] = "http://mydomain.com/image0.gif";
          
    image_url[1] = "http://mydomain.com/image1.gif";
          
    image_url[2] = "http://mydomain.com/image2.gif";
          
    image_url[3] = "http://mydomain.com/image3.gif";

           var 
    0;
           for(
    i=0i<=3i++) 
             
    preload_image_object.src image_url[i];
        }

        
    //-->
        
    </SCRIPT> 
    Thank for your help !

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    scandir()
    while
    and ++
    should be easy enough say if you need more help

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    it's the a++ that I have problem with.

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    it basically needs to be the same as the javascript you have
    $i = 0; $i < $files; $i++
    echo "// the javascript bit";

  • #5
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    PHP Code:
    <?php
    $image_counter 
    = -1;
    $row_counter 0;
    $cell_counter 0;
    $show=array('.jpg','.JPG','.gif','.GIF');
    $path 'Images/2/';


    $dir_handle = @opendir($path) or die("Unable to open $path");

    $image_table "<table valign=\"top\" align=\"center\">\n<tr><th colspan=3>Existing Pics in Directory:</th></tr>\n<tr>";
    while (
    false !== ($file readdir($dir_handle))) {
      if(
    in_array(substr($file,-4,4),$show)){
            if(!((
    $image_counter 1) % 3)){
              
    $row_counter++;
            }
    $newpath0 basename($file,".*");
          
    $image_table .=(($image_counter 1) % 3)? "" "</tr>\n<tr><td><br></td></tr><tr valign=\"top\">";
          
    $image_table .= "\n<td valign=\"top\"><table width=\"200\" border=\"1\" cellpadding=\"0\" cellspacing=\"1\" align=\"center\">\n";
          
    $image_table .= "\n<tr><td align=\"center\"><b>$newpath0</b></td></tr>\n";
          
    $image_table .= "\n<td><img src=\"$path$file\" width=\"200\"></td></tr>\n";
          
    $image_table .= "\n<tr><td></td></tr>\n";
          
    $image_table .= "\n<tr><td><b>Prix :</b> Test</td></tr>\n";
          
    $image_table .= "\n<tr><td><b>Prix :</b> Test</td></tr>\n";
          
    $image_table .= "\n<tr><td><b>Prix :</b> Test</td></tr>\n";
          
    $image_table .= "\n</table></td>\n";

          ++
    $image_counter;
          ++
    $cell_counter;
      }

    }
    $colspan= ($row_counter 3) - $cell_counter;
    $image_table .= ($cell_counter 3) ?  "<td colspan=$colspan>&nbsp;</td>" "";
    $image_table .= "</tr>\n</table>\n";
    echo 
    "$image_table<br><br>";
    echo 
    "<b>Total Cells w pics: $cell_counter<br>";
    echo 
    "<b>Total Rows: $row_counter<br>";
    echo 
    "<b>Empty Cells in last row: $colspan";
    ?>

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Peuplarchie View Post
    PHP Code:
    <?php
    $image_counter 
    = -1;
    $row_counter 0;
    $cell_counter 0;
    $show=array('.jpg','.JPG','.gif','.GIF');
    $path 'Images/2/';


    $dir_handle = @opendir($path) or die("Unable to open $path");

    $image_table "<table valign=\"top\" align=\"center\">\n<tr><th colspan=3>Existing Pics in Directory:</th></tr>\n<tr>";
    while (
    false !== ($file readdir($dir_handle))) {
      if(
    in_array(substr($file,-4,4),$show)){
            if(!((
    $image_counter 1) % 3)){
              
    $row_counter++;
            }
    $newpath0 basename($file,".*");
          
    $image_table .=(($image_counter 1) % 3)? "" "</tr>\n<tr><td><br></td></tr><tr valign=\"top\">";
          
    $image_table .= "\n<td valign=\"top\"><table width=\"200\" border=\"1\" cellpadding=\"0\" cellspacing=\"1\" align=\"center\">\n";
          
    $image_table .= "\n<tr><td align=\"center\"><b>$newpath0</b></td></tr>\n";
          
    $image_table .= "\n<td><img src=\"$path$file\" width=\"200\"></td></tr>\n";
          
    $image_table .= "\n<tr><td></td></tr>\n";
          
    $image_table .= "\n<tr><td><b>Prix :</b> Test</td></tr>\n";
          
    $image_table .= "\n<tr><td><b>Prix :</b> Test</td></tr>\n";
          
    $image_table .= "\n<tr><td><b>Prix :</b> Test</td></tr>\n";
          
    $image_table .= "\n</table></td>\n";

          ++
    $image_counter;
          ++
    $cell_counter;
      }

    }
    $colspan= ($row_counter 3) - $cell_counter;
    $image_table .= ($cell_counter 3) ?  "<td colspan=$colspan>&nbsp;</td>" "";
    $image_table .= "</tr>\n</table>\n";
    echo 
    "$image_table<br><br>";
    echo 
    "<b>Total Cells w pics: $cell_counter<br>";
    echo 
    "<b>Total Rows: $row_counter<br>";
    echo 
    "<b>Empty Cells in last row: $colspan";
    ?>
    is this working now then?

  • #7
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    no, this is the code I'm starting from you see it look trough a directory and display the image.

    I want to have those image to be preloaded how can i ?


  •  

    Posting Permissions

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