Reputation: 36
if have made a script that shows the contents of a folder but i wnat it not to show the folders and extensions.
does anyone know how to do this
// open this directory
$myDirectory = opendir("../website");
// get each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
// count elements in array
$indexCount = count($dirArray);
// sort 'em
sort($dirArray);
// print 'em
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<ul id=\"navb\" class=\"page\"><a href=\"?mp=$dirArray[$index]\">$dirArray[$index]</a></ul>");
print("\n");
}
}
Upvotes: 0
Views: 119
Reputation: 22797
You just need is_dir
and pathinfo()
.
foreach(glob( $myDirectory . '/*') as $file)
{
if( is_dir($file) || substr($file,0,1) == '.')
continue;
$info = pathinfo($file);
echo '<li>' . $info['filename'] .'</li>';
}
Upvotes: 3