Page 1 of 1

external javascript and php

Posted: Fri Dec 18, 2009 11:43 am
by chris24300
Hi, I have some code to take all picture in a directory and to post them on a website. The php side handles taking all images from a directory and outputs as js array element. My HTML and js code seem correct and rely on my gallery array which is never filled. here is the PHP, this may need to be placed in PHP programming section...

Code: Select all

 
<?
//PHP SCRIPT&#058; getimages.php
Header("content-type: application/x-javascript");
 
function returnimages($dirname=".") {
$pattern="(\.jpg$)|(\.jpeg$"); 
$files = array();
$image=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ 
echo 'gallery['.$curimage.']="'.$file .'";';
$image++;
}
}
closedir($handle);
}
return($files);
}
echo 'var gallery=new Array();'; 
returnimages() 
?> 
 
Thanks for the help,
Chris

Re: external javascript and php

Posted: Fri Dec 18, 2009 1:19 pm
by AbraCadaver
What is the HTML that you get?

Re: external javascript and php

Posted: Fri Dec 18, 2009 4:24 pm
by chris24300
I do not get any images appearing. I have gone through examples and the only thing I conclude is that there must be a problem with the PHP. Here is my HTML code

Code: Select all

 
<body>
<script type="text/javascript" src="images/getimages.php"></script>
<script type="text/javascript">
var curimg=0
function newestimg(){
document.getElementById("largethumb").setAttribute("src", "images/"+gallery[curimg])
curimg=(curimg<gallery.length-1)? gallery.length-1 : curimg
} 
window.onload=function(){
setInterval("newestimg()", 5000)
}
</script>
 
<table border="0" width="100%" cellpadding="10">
<tr>
<td width="50%" valign="top">
<div style="width:auto ; height:auto">
<img id="largethumb" src="" alt="mimg"/>
</div>
</td>
<td width="50%" valign="top">
<img name="01" src="" />
<img name="02" src="" />
<img name="03" src="" />
<img name="04" src="" />
<img name="05" src="" />
<img name="06" src="" />
<img name="07" src="" />
<img name="08" src="" />
<img name="09" src="" />
<img name="10" src="" />
<img name="11" src="" />
<img name="12" src="" />
 
<script type="text/javascript">
var i=0
var j=0
for(i=gallery.length-2; i>0; i--){
    document.images[j++].src="/images/"+gallery[i]
} // for
 
</script>
</td>
 
</tr>
</table>
 
</body>
 

Re: external javascript and php

Posted: Fri Dec 18, 2009 4:41 pm
by AbraCadaver
What do you get if you load images/getimages.php in a browser window?