...

View Full Version : preload image in $file ?!?!?!



Peuplarchie
07-27-2007, 02:26 AM
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 :




<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 i = 0;
for(i=0; i<=3; i++)
preload_image_object.src = image_url[i];
}

//-->
</SCRIPT>




Thank for your help !

rafiki
07-27-2007, 02:50 AM
scandir()
while
and ++
should be easy enough :D say if you need more help

Peuplarchie
07-27-2007, 03:20 AM
it's the a++ that I have problem with.

rafiki
07-27-2007, 03:24 AM
it basically needs to be the same as the javascript you have
$i = 0; $i < $files; $i++
echo "// the javascript bit";

Peuplarchie
07-27-2007, 04:34 AM
<?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";
?>

rafiki
07-27-2007, 01:16 PM
<?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?

Peuplarchie
07-27-2007, 11:33 PM
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 ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum