My PHP is not the best, but you can do something like so on most PHP servers (filename - get_slides.php):
PHP Code:
<?php header('Content-Type: text/javascript');
function returnimages($dirname="./images/") {
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
echo 'slides[' . $curimage .']=["' . $dirname . $file . '", "", ""];' . "\n";
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo "var slides=new Array();" . "\n";
returnimages();
?>
That will pick up the images in a folder called images of off the folder in which the above file is located, and define them as elements in the slides array. Then on a regular HTML or PHP page in the same folder as get_slides.php (not in the images folder), instead of defining the slides array in your code, link first to the external script:
HTML Code:
<script type="text/javascript" src="get_slides.php"></script>
Remember not to redefine the array named slides on your page or in other scripts linked to it.
Bookmarks