PHP - List All Directories In given Folder.

Status
Not open for further replies.

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Hey all,

So I'm trying to load all folders in folders/ folder and I'm using Metro UI. Means body's y overflow is hidden so I need to Show first 4 folders and switch to other div and show more 4. How may I do that?
Screenshot explaining:
P0zJtOSaRueq0WCo2VXdBw.png

My Code ATM :
PHP:
<?php 
$path = 'folders/'; 
$files = glob($path . '*');
foreach ($files as $file) {

    if(is_dir($file)) {
       
        ?> 
 <a href="<?= $file; ?>" class="tile bg-indigo fg-white" data-role="tile">
                    <div class="tile-content iconic">
                        <span class="icon mif-folder"></span>
                    </div>
                    <span class="tile-label"><?= $file; ?></span>
                </a>
        <?php 
    }

    }
 ?>
Thanks.
 
Oh Also, I want to show only For example CMS, not folder/CMS.
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
PHP:
<?php
foreach (glob("folders/*", GLOB_ONLYDIR) as $file) {
    print "<a href='$file' class='tile bg-indigo fg-white' data-role='tile'>
  <div class='tile-content iconic'>
    <span class='icon mif-folder'></span>
  </div>
  <span class='tile-label'>$file</span>
</a>";
}
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
PHP:
<?php
foreach (glob("folders/*", GLOB_ONLYDIR) as $file) {
    print "<a href='$file' class='tile bg-indigo fg-white' data-role='tile'>
  <div class='tile-content iconic'>
    <span class='icon mif-folder'></span>
  </div>
  <span class='tile-label'>$file</span>
</a>";
}

thats not I've asked for. If you can explain with some examples, I'll be more happy then.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
<?php
foreach (glob('folders/*', GLOB_ONLYDIR) as $file) {
    print "<a href='$file' class='tile bg-indigo fg-white' data-role='tile'>
  <div class='tile-content iconic'>
    <span class='icon mif-folder'></span>
  </div>
  <span class='tile-label'>$file</span>
</a>";
}
It's better to inverse the single/double quotes, so the HTML being outputted is HTML5 valid.

PHP:
<?php
foreach (glob("folders/*", GLOB_ONLYDIR) as $file) {
    echo '<a href="' . $file . '" class="tile bg-indigo fg-white" data-role="tile">
  <div class="tile-content iconic">
    <span class="icon mif-folder"></span>
  </div>
  <span class="tile-label">' . $file . '</span>
</a>';
}
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
It's better to inverse the single/double quotes, so the HTML being outputted is HTML5 valid.

PHP:
<?php
foreach (glob("folders/*", GLOB_ONLYDIR) as $file) {
    echo '<a href="' . $file . '" class="tile bg-indigo fg-white" data-role="tile">
  <div class="tile-content iconic">
    <span class="icon mif-folder"></span>
  </div>
  <span class="tile-label">' . $file . '</span>
</a>';
}
This one works, but the point is I only want to show first 4 folders then jump to next div. How can I do that?
What you want is more of a CSS thing, set the max-height of the div?
I don't want to edit height because it looks best right now.
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
And to remove the folder/ just use

PHP:
<?php
foreach (glob("folders/*", GLOB_ONLYDIR) as $file) {
    $file = basename($file);
    print "<a href='$file' class='tile bg-indigo fg-white' data-role='tile'>
  <div class='tile-content iconic'>
    <span class='icon mif-folder'></span>
  </div>
  <span class='tile-label'>$file</span>
</a>";
}
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
This one works, but the point is I only want to show first 4 folders then jump to next div. How can I do that?

I don't want to edit height because it looks best right now.
He means you need to change the height of the parent div, so the boxes get pushed to the right.
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
And to remove the folder/ just use

PHP:
<?php
foreach (glob("folders/*", GLOB_ONLYDIR) as $file) {
    $file = basename($file);
    print "<a href='$file' class='tile bg-indigo fg-white' data-role='tile'>
  <div class='tile-content iconic'>
    <span class='icon mif-folder'></span>
  </div>
  <span class='tile-label'>$file</span>
</a>";
}
This fixed
Oh Also, I want to show only For example CMS, not folder/CMS.
This,
Now how to show first 4 folders and jump to next div :p
 
He means you need to change the height of the parent div, so the boxes get pushed to the right.
That didn't work actually, set it to even 100 px but doesn't work .
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Alright, fixed that by adding a 'triple' class to main div, thanks both to @Northyy and @Wess . It looks like this now, as I wanted:


If anyone needs code, here you go :
PHP:
  <div class="tile-group triple" style="max-height: 100px;">
            <span class="tile-group-title">Folders</span>

            <div class="tile-container" >

<?php
foreach (glob("folders/*", GLOB_ONLYDIR) as $file) {
    $file = basename($file);
    print "<a href='$file' class='tile bg-indigo fg-white' data-role='tile'>
  <div class='tile-content iconic'>
    <span class='icon mif-folder'></span>
  </div>
  <span class='tile-label'>$file</span>
</a>";
}
?>
           
               

             
            </div>
        </div>
 
Status
Not open for further replies.

Users who are viewing this thread

Top