PHP
26
prohibit
Guest on 20th June 2022 04:31:32 PM
<?php
/////////////////////////////////
// A directory listing snippet //
/////////////////////////////////
/* This assumes that the $dir /
/ variable is already set. */
/////////////////////////////////
$disallowedFiles
while ($conteudo = readdir($dir)) {
echo "<a href=./$conteudo>$conteudo</a><br>";
}
?>
<?php
$prohibited = array( // An array, with Regexp patterns to match prohibited files
'/^\./', // No *NIX hidden files... this also drops .htaccess, as well as ".", ".." entries
'/^htaccess\.txt$/', // Some servers call it "htaccess.txt"
'/^index\.php$/'); // Also drop your index.php file
foreach($prohibited as $thisProhibited)
$listing = preg_grep($thisProhibited, $listing, PREG_GREP_INVERT
);
// see http://www.php.net/manual/en/function.preg-grep.php Note 1
// I'm not sure if PREG_GREP_INVERT is fully supported. YMMV.
}
foreach($listing as $thisDirItem)
{
echo "<a href=\"$thisDirItem\">$thisDirItem</a><br>";
// spit out the list, minus everything we removed above
}
?>