Page 1 of 1

PHP sends my site into an endless loop. (Slideshow)

Posted: Thu Jul 24, 2008 3:18 am
by t0nka
Hi,

I am using the following code to loop through the filenames of a folder and add them into a javascript array for use in my slideshow. This works fine, but once the first loop displaying the images is finished, it sends the site into an endless loop tryinh to download the files..

servername/css/loader-1.png
servername/css/loader-2.png ... etc all the way upto servername/css/loader-11.png

Which are the files that are used by the slideshow.

Code: Select all

<?php
$addarray = array();
$x = 0;
if ($handle = opendir('slideshow')) {
    while (false !== ($file = readdir($handle))) { 
        if ($file != "." && $file != "..") {
            $file_name=substr($file, 0, strpos($file, "."));
                if ( $file_name != "")
                {
                $addarray[$x] = "$file_name.jpg";
                $x = $x + 1;
                }
    }
}
}
closedir($handle); 
?>
 
    <script type="text/javascript">     
    //<![CDATA[
      window.addEvent('domready', function(){
        var data =new Array("<?=implode("\",\"", $addarray); ?>") 
        // Initialize the Slideshow instance
        var myShow = new Slideshow('show', data, { height: 240, hu: 'images/', width: 300 });
      });
    //]]>
    </script>
Coudl someone please have a look at my code an see if they could spot where it is going wrong.

Thanks

Tom

Re: PHP sends my site into an endless loop. (Slideshow)

Posted: Mon Jul 28, 2008 7:22 pm
by andychamberlainuk
i've only had a quick glance but this could be the problem: -

Code: Select all

while (false !== ($file = readdir($handle))) {
it should be: -

Code: Select all

while (false != ($file = readdir($handle))) {