Forum Moderators: coopster
CODE:
<script type="text/javascript">
......
......
// array to specify images and optional links. At least 4
// If Link is not needed keep it ""
Book_Image_Sources=new Array(
"photo1.jpg","http://www.example.com",
"photo2.jpg","http://www.example.com",
"photo3.jpg","", //this slide isn't linked
"photo4.jpg","http://www.example.com"
);
..........
..........
</script>
<div id="Book" style="position:relative">
<img src="placeholder.gif" width="144" height="227">
</div>
-----------------------------------------------------------------
This above code is inserted in BODY section of the page where slideshow will appear.
An onload event handler is called from inside the <BODY> tag itself:
<body onload="ImageBook()">
Now here's my issue:
As you can see this script uses a statically defined array(Book_Image_Sources). But I want to use dynamic array i.e., I want to use PHP to read a particular directory containing the images, create the array with the image list and use that image array in the script to display the slide show.
Please help me out. Thanx in advance.
[edited by: coopster at 2:47 am (utc) on April 16, 2007]
[edit reason] no urls please TOS [webmasterworld.com] [/edit]
Place this all as one lump where you've got the current declaration of Book_Image_Sources.
<?php
// this is the path to the images as seen by a browser
$htmlbase = "http://example.com/images/";
// this would be the directory path, something like home/yourusername/public_html/images
$hdl = opendir('path/to/images');
$imgs = '';
while($filename = readdir($hdl))
$imgs .= '"' . $htmlbase . $filename . '"' . ',"",';
$imgs = substr($filename,0,-1);
?>
Book_Image_Sources=new Array(<?php echo $imgs;?>);
Depending on how that script is written you may not need $htmlbase - if you specify it elsewhere in the script, for example. If so, change the line:
$imgs .= '"' . $htmlbase . $filename . '"' . ',"",';
to
$imgs .= '"' . $filename . '"' . ',"",';
and you can remove its declaration line (or leave it, it wouldn't do any harm).