Hey
I got this code where the PHP generates an Javascript array, but it isn’t working. Or I don’t get it.
This is the PHP Getimages.php (It generates an javascript array with filenames)
<?
//PHP SCRIPT: getimages.php
//Header("content-type: application/x-javascript");
//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname="img/gallery/") {
$pattern="(\\.jpg$)|(\\.png$)|(\\.jpeg$)|(\\.gif$)"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'fadeimages2['.$curimage.']=["'.$dirname . $file.'"];'."\
";
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo 'var fadeimages2=new Array();'."\
"; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
/* THE Array should look like this
var fadeimages2=new Array()
fadeimages[0]=["img/gallery/01_2.jpg"]
fadeimages[1]=["img/gallery/02_2.jpg"]
fadeimages[2]=["img/gallery/03_2.jpg"]
*/
?>
This is the main page, so the javascript array should be echoed in this script.
<div id="container">
<div id="slideshow">
<script type="text/javascript">
<?
require_once('getimages.php');
?>
new fadeshow(fadeimages2, 355, 210, 0, 5000, 0);
</script>
</div>
Here’s the page:
http://web.zone.ee/testcss/
But it somewhy doesn’t do what it’s supposed to do i think. Please help.
I don’t see where the problem is. Why doesn’t that javascript slideshow engine show pictures.