external javascript and php

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
chris24300
Forum Newbie
Posts: 2
Joined: Fri Dec 18, 2009 11:27 am

external javascript and php

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: external javascript and php

Post by AbraCadaver »

What is the HTML that you get?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
chris24300
Forum Newbie
Posts: 2
Joined: Fri Dec 18, 2009 11:27 am

Re: external javascript and php

Post 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>
 
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: external javascript and php

Post by AbraCadaver »

What do you get if you load images/getimages.php in a browser window?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply