External JavaScript and PHP to rotate through folder of images
<p>I'm trying to use Javascript and PHP to read a folder of images and cycle through the images.
I got the idea and code from here: <a href="http://www.javascriptkit.com/javatutors/externalphp2.shtml" rel="nofollow">http://www.javascriptkit.com/javatutors/externalphp2.shtml</a></p>

<p>I'm not getting any errors even with Firebug up. But it's just not cycling through the images. It loads the first image that I set (userfiles/portfolio/0025.jpg). But doesn't ever move to another image.</p>

<p>The getimages.php is located in userfiles/portfolio along with my images.</p>

<p>Here's what I have:</p>

<p>On the page I want to display the images:</p>

<pre><code>&lt;script src="userfiles/portfolio/getimages.php"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;

var curimg=0
function rotateimages(){
document.getElementById("slideshow").setAttribute("src", "userfiles/portfolio/"+galleryarray[curimg])
curimg=(curimg&lt;galleryarray.length-1)? curimg+1 : 0
}

window.onload=function(){
setInterval("rotateimages()", 1000)
}
&lt;/script&gt;

&lt;div id="portfoilo"&gt;
    &lt;img id="slideshow" src="userfiles/portfolio/0025.jpg" /&gt;
&lt;/div&gt;
</code></pre>

<p>and here is my getimages.php </p>

<pre><code> &lt;?php
//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=".") {
    $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 'galleryarray['.$curimage.']="'.$file .'";';
            $curimage++;
            }
        }

            closedir($handle);
        }
    return($files);
}

echo 'var galleryarray=new Array();'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?&gt; 
</code></pre>

<p>getimages.php was showing up blank when I ran it.  However now I'm getting:</p>

<pre><code>&lt;font size='1'&gt;&lt;table class='xdebug-error xe-deprecated xe-scream' dir='ltr' border='1' cellspacing='0' cellpadding='1'&gt;
&lt;tr&gt;&lt;th align='left' bgcolor='#f57900' colspan="5"&gt;&lt;span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'&gt;( ! )&lt;/span&gt; SCREAM: Error suppression ignored for&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th align='left' bgcolor='#f57900' colspan="5"&gt;&lt;span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'&gt;( ! )&lt;/span&gt; Deprecated: Function eregi() is deprecated in J:\My Documents\Dropbox\www\ChiseledImages-Ras\userfiles\portfolio\getimages.php on line &lt;i&gt;13&lt;/i&gt;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th align='left' bgcolor='#e9b96e' colspan='5'&gt;Call Stack&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th align='center' bgcolor='#eeeeec'&gt;#&lt;/th&gt;&lt;th align='left' bgcolor='#eeeeec'&gt;Time&lt;/th&gt;&lt;th align='left' bgcolor='#eeeeec'&gt;Memory&lt;/th&gt;&lt;th align='left' bgcolor='#eeeeec'&gt;Function&lt;/th&gt;&lt;th align='left' bgcolor='#eeeeec'&gt;Location&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td bgcolor='#eeeeec' align='center'&gt;1&lt;/td&gt;&lt;td bgcolor='#eeeeec' align='center'&gt;0.0014&lt;/td&gt;&lt;td bgcolor='#eeeeec' align='right'&gt;248760&lt;/td&gt;&lt;td bgcolor='#eeeeec'&gt;{main}(  )&lt;/td&gt;&lt;td title='J:\My Documents\Dropbox\www\ChiseledImages-Ras\userfiles\portfolio\getimages.php' bgcolor='#eeeeec'&gt;..\getimages.php&lt;b&gt;:&lt;/b&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td bgcolor='#eeeeec' align='center'&gt;2&lt;/td&gt;&lt;td bgcolor='#eeeeec' align='center'&gt;0.0015&lt;/td&gt;&lt;td bgcolor='#eeeeec' align='right'&gt;249536&lt;/td&gt;&lt;td bgcolor='#eeeeec'&gt;returnimages(  )&lt;/td&gt;&lt;td title='J:\My Documents\Dropbox\www\ChiseledImages-Ras\userfiles\portfolio\getimages.php' bgcolor='#eeeeec'&gt;..\getimages.php&lt;b&gt;:&lt;/b&gt;26&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/font&gt;
</code></pre>

<p>Is eregi completely gone now? I know it was being deprecated after 5 and my WAMP version is running php 5.4.3.  </p>
