Solution:2
I think this would do the trick. Post a request to the server (through AJAX). The server returns the path to all files with commas to separate them, once back on the client jQuery splits this string of data at the commas and puts the full paths in an array. When this is done you can simply loop through the array and create an image element for every element of the array, or do whatever you want.
The PHP file
<?php
function ListFiles($dir) {
if($dh = opendir($dir)) {
$files = Array();
$inner_files = Array();
while($file = readdir($dh)) {
if($file != "." && $file != ".." && $file[0] != '.') {
if(is_dir($dir . "/" . $file)) {
$inner_files = ListFiles($dir . "/" . $file);
if(is_array($inner_files)) $files = array_merge($files, $inner_files);
} else {
array_push($files, $dir . "/" . $file);
}
}
}
closedir($dh);
return $files;
}
}
foreach (ListFiles('wp-content/uploads') as $key=>$file){
echo $file .",";
}
?>
SOURCE: http://tycoontalk.freelancer.com/php-forum/41811-list-files-in-directory-sub-directories.html#post202723
jQuery:
$(function(){
$.post("getallfiles.php",{/*post data to server if needed*/}, function(data){
//Splitting with comma expecting it not to be in filenames and directory names.
var uploads = data.split(',');
//uploads[0] would return the first image's path if I'm correct.
})
});
I think this works, I didn’t try it out though, all you need to do is loop through the uploads array and do whatever you want with the imagepath.