Friday 11 July 2014

How to get all directory name of root in php


Before Starting...

Know about file location

       My File exist in C:\xampp\htdocs\ftp\index.php
In ftp directory we have  6 more directories  names are :
  • John
  • Jill
  • Cafe
  • Monit
  • Rifle
  • Kim.
we want to know all the directory name by uisng index.php
<?php
$ar = array();
$directory = "./";
$files = glob($directory . "*", GLOB_ONLYDIR );
foreach($files as $file)
{

$ar[] =  basename($file);
}
 
$a =count($ar);
for($i=0;$i<$a;$i++)
{
echo $ar[$i]."<br>";
}  

Output Will be
John
Jill
Cafe
Monit
Rifle
Kim.



No comments:

Post a Comment