phpcodeignitersystem-paths

Get file-name in sub-folders along with its information in controller


I have a 'images' folder and inside it are subfolders which have images. What I want is the name all the images along with their path in an array.

I have written this in my controller:

$data['images_names'] = directory_map('../project/images/');

this is giving be image name, but not path. Can anyone tell me how can I achieve that?

Thanks in advance....


Solution

  • what about this ??

    $files = dir_scan('/var/www/www/chat/*');
    print_r($files);
    
    function dir_scan($folder) {
      $files = glob($folder);
      foreach ($files as $f) {
        if (is_dir($f)) {
          $files = array_merge($files, dir_scan($f . '/*')); // scan subfolder
        }
      }
      return $files;
    }
    

    from

    PHP get path to every file in folder/subfolder into array?