Reputation: 5826
I'm trying to achieve dynamic image loading from FTP server, but I have no clue how to make it work.
What I need is a PHP script which would pull images from my ftp server and create the HTML structure of this images with the paths and extension of them.
Upvotes: 1
Views: 3954
Reputation: 1688
I think what you are looking for is the PHP glob() function.
I would have a new php file image_get.php.
With contents something like this:
<?php
$directory = "images/gallery";
foreach (glob($directory."/*.png") as $image) {
echo '<a href="'.$image .'"><img src="'.$image .'"></a>';
}
?>
Then an ajax call the image_get.php file like so:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$(document).ready(function() {
$.ajax('image_get.php').done(function(data){
$("#images").html(data);
});
});
</script>
Then in body of your html page have a div tag with an id equal to images
.
You will have to make some changes to add classes to elements and to get all images, atm the glob()
function is just returning all files in the directory with a extension of .png
.
Ref:
PHP: http://php.net/manual/en/function.glob.php
Jquery: http://api.jquery.com/jquery.ajax/
Upvotes: 0