Hi all, first post.
I have been trying to create a dynamic gallery to fit in with my existing site and had originally used pure javascript to code the gallery, but I'm getting fed up with having to continually edit the js file, so I thought php would be easiest, I have reworked a script I found to search my diectories, but I can't figure out how to output as a javascript array,
I can get it to list all items as:
/foldername[0] = "imagename.jpg"
but I need it to be formatted as:
array((foldername(0))
so I can put the php in my jscript file instead of a complete rewrite, I'm new to both jscript and php so any help would be much appreciated.
my php code:
<?php
function recursive_dir($root,$path_ext = "",$check_ext = "",$new_path_ext = "") {
$dh = opendir($root.$path_ext.$new_path_ext);
while(false !== ($entry=readdir($dh))) {
if($entry != "." && $entry != ".." && is_dir($root.$path_ext.$new_path_ext."/".$entry)) {
$prev_path_ext = $new_path_ext;
$new_path_ext .= "/".$entry;
recursive_dir($root,$path_ext,$check_ext,$new_path_ext);
$new_path_ext = $prev_path_ext;
}
elseif($entry != "." && $entry != ".." && eregi("($check_ext)$",$entry)) {
$curimage=0;
if($dh = opendir($root.$path_ext.$new_path_ext)) {
while(false !== ($entry = readdir($dh))){
//Output it as a JavaScript array element
echo $new_path_ext;
echo '['.$curimage.']';
echo '='.$entry .'<br />';
$curimage++;
}
}
}
}
closedir($dh);
}
recursive_dir($root_directory,$path_extension,$check_extension);
echo ' need output to look like this:<br />arrayname(foldername(number of items))';
?>