external javascript and php
Posted: Fri Dec 18, 2009 11:43 am
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...
Thanks for the help,
Chris
Code: Select all
<?
//PHP SCRIPT: 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()
?>
Chris