0

I´m trying to make an image gallery reading images from FTP folder, but the result is this:

enter image description here

How can I make it? The following code is:

$ftp_server = "...";
$ftp_user_name = "...";
$ftp_user_pass = "...";
$remote_dir = "/www/wp-content/themes/seller-child/setas/";

$conn_id = ftp_connect($ftp_server);
$login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if($login_result) {
ftp_pasv($conn_id, true);
}

if(!@ftp_chdir($conn_id, $remote_dir)) {
ftp_chdir($conn_id, $remote_dir);
}

$files = ftp_nlist($conn_id , $remote_dir);
foreach ($files as $value) {
echo "<img src='$value'/>";
}

I tried also this way, but it has same result

$directory='wp-content/themes/seller-child/setas';      
if (is_dir($directory)){        
$dirint = dir($directory);      
    while (($archivo = $dirint->read()) !== false)       
    {        
     if (eregi($reg_exp, $archivo)){
         echo $archivo . PHP_EOL;
     echo '<img src="'.$directory."/".$archivo.'">'."\n";
         echo '<br/>';
         }       
     }  

   $dirint->close();
   }
  • How do you expect this to work? `ftp_nlist` "Returns a list of files in the given directory" - **on the remote FTP server**. For the end user to download those files they would need to log in to the ftp server as well. – Mike May 22 '16 at 19:38
  • 1
    You would either need to do something like [this](http://stackoverflow.com/questions/17169251/retrieve-image-from-ftp-to-webpage) (which means you need to give the FTP password out), or use PHP to download the file to your server and echo the contents back to the user (and hopefully cache it since I would imagine an FTP connection would be a big bottleneck in your script). – Mike May 22 '16 at 19:41
  • @Mike I only want to load images from the specified ftp folder, but i don't know if that's the correct way to make it. I tried reading the specified folder without using ftp methods, but it had same result.. –  May 22 '16 at 19:45
  • If you don't want to load the images, what are you actually trying to do? – Mike May 22 '16 at 19:46
  • @Mike No, i just want to load them in my webpage, but i don´t know the way to do it, I only tried that way –  May 22 '16 at 19:47
  • So look at my second comment. I gave you 2 options. – Mike May 22 '16 at 20:03
  • @Mike some files are hosted in a FTP folder, rest are hosted in Wordpress folder, but I just want to display (sorry, I told load but i wanted to tell display) FTP folder ones on the webpage. I read the link you posted I know that this it's no the correct way, but I´m only trying –  May 22 '16 at 20:10
  • @Mike just read it, but how can I download files to server? I´ve searched before ftp_get, but doesn't it download file literally to a local file? –  May 22 '16 at 20:17
  • Yes, that's what it does. That's what you want. Then use PHP to read the contents of that file and output it to the browser. So for example you would do `` and then get_image.php would output the content of that file. – Mike May 22 '16 at 20:41
  • Possible duplicate of [Retrieve image from FTP to webpage](https://stackoverflow.com/questions/17169251/retrieve-image-from-ftp-to-webpage) – Martin Prikryl Oct 19 '18 at 11:21

0 Answers0