10 items total: 7 items with no file extension, 3 items with a file extension.
DOT files, or Unix hidden files, are deliberately excluded from this list. The directory listing can be omitted, or can be linked by following the examples shown here. By expanding these examples it would also be possible to only display a select list of file extension types, such as PDF or DOC.
<?php
// read this directory
$thisDir = substr($_SERVER['PATH_TRANSLATED'],0,strrpos($_SERVER['PATH_TRANSLATED'],'/'));
$cntFile = 0; // start file counter, names that have an extension
$cntDir = 0; // start directory counter, names with no extension
$dlist = ''; // build the resulting list and then echo the final results
// 1st run: generate the list of files with no filename extension
if ($dir = @opendir($thisDir)) { // open a specified directory
$dlist .= "\n" . '<h3>Directory/Other <small style="font-weight:500;">';
$dlist .= '(Items with no Filename Extension)</small></h3>' . "\n" . '<ul>';
while ($file = @readdir($dir)) { // read a name from the directory
if (strpos(' '.$file,'.') != 1 && !strpos(' '.$file,'.')) { // if a dir
$dlist .= "\n" . '<li>' . htmlentities($file) . '</li>';
$cntDir += 1; // increment the counter
}
}
if ($cntDir < 1) $dlist .= "\n" . '<div><small>(none)</small></div>';
$dlist .= "\n" . '</ul>';
closedir($dir); // close the directory
}
// 2nd run: generate the list of files that have filename extensions
if ($dir = @opendir($thisDir)) { // open a specified directory
$dlist .= "\n" . '<h3>Mime Type Files <small style="font-weight:500;">';
$dlist .= '(Items that have Filename Extensions)</small></h3>' . "\n" . '<ul>';
while ($file = @readdir($dir)) { // read a name from the directory
if (strpos($file,'.') != 0) { // if a file and not a DOT file
$dlist .= "\n" . '<li><a href="' . htmlentities($file) . '">';
$dlist .= htmlentities($file) . '</a></li>';
$cntFile += 1; // increment the counter
}
}
if ($cntFile < 1) $dlist .= "\n" . '<div><small>(none)</small></div>';
$dlist .= "\n" . '</ul>';
closedir($dir); // close the directory
} else $dlist .= "\n" . '<p>(Could not read the directory, or the directory does not exist.)</p>';
echo '<h2>Directory Contents</h2>';
if ($cntFile+$cntDir > 0) { // items found, any file or directory
echo "\n" . '<p>';
if ($cntFile > 0 && $cntDir > 0) { // files and directories found
echo '<strong>' . ($cntFile + $cntDir) . ' item';
echo (($cntFile + $cntDir > 0) ?'s':'') . ' total:</strong> ';
}
if ($cntDir > 0) { // directories found
echo $cntDir . ' item' . (($cntDir > 0)? 's':'') . ' with no file extension';
}
if ($cntFile > 0 && $cntDir > 0) { // files and directories found
echo ', ';
}
if ($cntFile > 0) { // files found
echo $cntFile . ' item' . (($cntFile > 0) ?'s':'') . ' with a file extension';
}
echo '.</p>';
} else echo "\n" . '<div><small>(directory empty)</small></div>';
echo $dlist;
echo '<p>
DOT files, or Unix hidden files, are deliberately excluded from this list.
The directory listing can be omitted, or can be linked by following the
examples shown here. By expanding these examples it would also be possible
to only display a select list of file extension types, such as PDF or DOC.
</p>';
// -------- Show Source Code --------
echo "\n\n" . '<hr /><h2>The Source Code</h2>' . "\n\n";
highlight_file($_SERVER['PATH_TRANSLATED']);
?>