0

I'm trying to get all the map names form a directory (path) in laravel 4.2.

So I have a path public\pictures\overall and in that folder there are alot of other folders named like this-is-folder-one so the spaces are -. Now I want to get all the folder names with spaces and no the - symbol.

I tried alot of methods like glob(); etc... But everytime it gives me the full path, and I don't want to have that.

Optionally I would Add and image to it (thumbnail) with a folder image. But that isn't necessary.

Hope someone can help me fulley out of this. (maybe the view and the controller?)

Kindest regards, Robin

Robin
  • 1,567
  • 3
  • 25
  • 67

2 Answers2

0

Try this from here:

foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('public\pictures\overall')) as $filename)
{
    // filter out "." and ".."
    if ($filename->isDir()) continue;

    echo str_replace('-', ' ', $filename) . PHP_EOL;
}
Community
  • 1
  • 1
Pawel Bieszczad
  • 12,925
  • 3
  • 37
  • 40
  • Then it displays this: `public\pictures\overall\TAC Tielt 2013\11128407_375183789338691_153976993_n.jpg public\pictures\overall\TAC Tielt Shakedown 2015\11080785_10206506352528367_7820067205477003786_o.jpg public\pictures\overall\TAC Tielt Shakedown 2015\11128744_10206506352568368_6443749205764096112_o.jpg public\pictures\overall\TAC Tielt Shakedown 2015\11129717_10206506352408364_3521420424335205794_o.jpg ` I wnt the `folder` names, not the file names. – Robin Aug 17 '15 at 14:59
0

Fixed by myself.

PHP:

$folders = array();
        foreach(glob('public\pictures\overall\*', GLOB_ONLYDIR) as $dir) {
          $base = basename($dir);
          if ($base == '.' || $base == '..') continue;
          $folders [] = $base;
        }

HTML:

@foreach ($folders as $folder)
    <li>{{ str_replace('-', ' ', $folder) }}</li>
@endforeach

Thanks for the help!

Robin
  • 1,567
  • 3
  • 25
  • 67