Home » Php » PHP -Loop on folder in a FTP SERVER

PHP -Loop on folder in a FTP SERVER

Posted by: admin February 25, 2020 Leave a comment

Questions:

i have added this but that doesn’t work…

$dir = "www/prod/Visuel/"; 
$path = realpath('www/prod/Visuel/'); 
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); 
foreach($objects as $name => $object) { 
 $img = $path;
How to&Answers:

RecursiveDirectoryIterator usage example (from the docs)

Usage example:

<?php

$path = realpath('/etc');

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
    echo $name . '<br>;
}

https://www.php.net/manual/en/class.recursivedirectoryiterator.php#85805

This prints a list of all files and directories under $path (including $path ifself). If you want to omit directories, remove the RecursiveIteratorIterator::SELF_FIRST part.