user1704671
user1704671

Reputation: 19

How to get urls of images from your ftp folder using php

I wanted to get URLs of images that are in my upload directory of my ftp server and save them into array using PHP script. After I do that I want to show those images as thumbnails. This is what I was trying

<?php 

$conn = ftp_connect("ftp.something.com") or die("Could not connect");
ftp_login($conn,"user","pass");

$images = array(ftp_nlist($conn,"upload"));
echo '$images';

for($i=0;$i<20;$i++) {
    echo"<img src='$images[$i]'>";
}
ftp_close($conn);

?>

Upvotes: 1

Views: 3432

Answers (1)

jeroen
jeroen

Reputation: 91734

ftp_nlist already returns an array, so if you put that in an array, you get a multidimensional array with only one element at index 0.

You should just use:

$images = ftp_nlist($conn,"upload");

And then to check its contents:

var_dump($images);

Also note that to use your list in html, you would need to add the server address (if it is not on the same server) and path:

echo"<img src='http://www.some_server.com/upload/{$images[$i]}'>";

Upvotes: 3

Related Questions