• 0

PHP - GetDirectories


Question

Hey Guys & Girls!

 

I'm fairly new to PHP, and I've been rollin' through the Codecademy courses, but it's not enough


I've been Googling around, looking for a good source of information, but I haven't found what I'm looking for. I guess you could say I'm wanting an "idiots guide to this issue".

I'm trying to show all the directories in x file i.e.

https://www.neowin.net/media

Any subfolder within that "media" folder would be listed in Alphabetical order. I feel bad for posting here with my level of knowledge. I just need a nudge in the right direction. I prefer to learn by doing, but this is a bit of a stretch for me. :(

 

Apologies if this isn't the right section!

Link to comment
Share on other sites

Recommended Posts

  • 0

So I changed the index.php file, and it looks a whole lot better. I think I need to hold off on this. I don't like having other people do my work for me, I learn nothing that way. Codecademy is awesome, it's just hard to use at work, constantly losing connection to their server and stuff not working right. =(

 

Media

 

This is what it looks like now. I had to tweak/comment things out to get it, lol.

Link to comment
Share on other sites

  • 0

So I changed the index.php file, and it looks a whole lot better. I think I need to hold off on this. I don't like having other people do my work for me, I learn nothing that way. Codecademy is awesome, it's just hard to use at work, constantly losing connection to their server and stuff not working right. =(

 

Media

 

This is what it looks like now. I had to tweak/comment things out to get it, lol.

 

There really is nothing to this and doesn't require much research or learning. it is literally 1 line of code.

foreach(glob('*') as $item)
{
  echo $item.'<br>';
}

Now if you want to just list directories then you can add a 2nd perimeter to glob() like so:

foreach(glob('*', GLOB_ONLYDIR) as $item)
{
  echo $item.'<br>';
}
Link to comment
Share on other sites

  • 0

 

There really is nothing to this and doesn't require much research or learning. it is literally 1 line of code.

foreach(glob('*') as $item)
{
  echo $item.'<br>';
}

Now if you want to just list directories then you can add a 2nd perimeter to glob() like so:

foreach(glob('*', GLOB_ONLYDIR) as $item)
{
  echo $item.'<br>';
}

I've only just started learning PHP, and I'm having trouble remembering simple things, like arrays, and functions. I know it's a lot like C++ where you have to declare something, i.e. #include iostream or x = 3, so when you do an if statement, if x > 10 then.. You get the point right? I'll see how glob works compared to the other one when I wake up in 8 hours. My days off fly by :(

Link to comment
Share on other sites

  • 0

I've only just started learning PHP, and I'm having trouble remembering simple things, like arrays, and functions. I know it's a lot like C++ where you have to declare something, i.e. #include iostream or x = 3, so when you do an if statement, if x > 10 then.. You get the point right? I'll see how glob works compared to the other one when I wake up in 8 hours. My days off fly by :(

 

Don't worry about it, I've been using PHP for years and still randomly forget functions,this is what the PHP documentation is for. http://php.net/manual/en/function.glob.php

Link to comment
Share on other sites

This topic is now closed to further replies.