I am trying to display images on a webpage as a gallery but i only want albums, each folder is an album and you select the album with the link menu so i parse the path to a function that then should then run a php script to return all the names of the images in that album, so far this is what i have.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2 /jquery.min.js"></script>
<div id="content-container" style="height: 500px;">
<div id="content" style="height: 500px;">
<div style="float: left; width: 200px;">
<h1> <span>The Gallery</span> </h1>
<ul id="nav">
<li><a href="" id="here">Gallery</a>
<ul>
<li><a href="" data-albumid="images/gallery/fld01">photos</a>
</li>
<li><a href="" data-albumid="images/gallery/fld02">photos</a>
</li>
<li><a href="" data-albumid="images/gallery/fld03">photos</a>
</li>
<li><a href="" data-albumid="images/gallery/fld04">photos</a>
</li>
</ul>
</li>
<li><a href="index.html">Back to home</a>
</li>
</ul>
</div>
<div class="album-container"></div>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
var id = $(this).data("albumid");
$(".album-container").empty();
LoadGallery(id);
return false;
});
});
function LoadGallery(id) {
alert('Loading gallery #' + id);
$(".album-container").load("getimages.php?dirpath=id,function() {
var reciverParameters = $(".album - container ").html();
var parser = new Array();
parser = reciverParameters.split(", ");
alert(parser);
})
/*
var curimg=0
function rotateimages(){
document.getElementById("
album - container ").setAttribute("
id "+galleryarray[curimg]);
curimg=(curimg<galleryarray.length-1)? curimg+1 : 0;
}
window.onload=function(){
setInterval("
rotateimages()
", 2500)
}
})
*/
}
</script>
<div class="clear"></div>
</div>
</div>
PHP:
<?
//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");
$dirname = $_get['dirpath'];
function returnimages($dirname) {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
$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
?>
$.post( url ... ) or $.get( url ... )