pastebin

Paste Search Dynamic
Recent pastes
A directory listing snippet
  1. <?
  2.  
  3. /////////////////////////////////
  4. // A directory listing snippet //
  5. /////////////////////////////////
  6. /* This assumes that the $dir   /
  7. /  variable is already set.    */
  8. /////////////////////////////////
  9.  
  10.  
  11. $disallowedFiles
  12.  
  13. while ($conteudo = readdir($dir)) {
  14.   echo "<a href=./$conteudo>$conteudo</a><br>";
  15.  
  16. }
  17.  
  18. closedir($dir);
  19. ?>
  20.  
  21. <?php
  22.  
  23. $prohibited = array(    // An array, with Regexp patterns to match prohibited files
  24.    '/^./',             // No *NIX hidden files... this also drops .htaccess, as well as ".", ".." entries
  25.    '/^htaccess.txt$/',  // Some servers call it "htaccess.txt"
  26.    '/^index.php$/');   // Also drop your index.php file
  27.  
  28. $listing = scandir($dir);
  29.  
  30. foreach($prohibited as $thisProhibited)
  31.    $listing = preg_grep($thisProhibited, $listing, PREG_GREP_INVERT);
  32.    // see http://www.php.net/manual/en/function.preg-grep.php Note 1
  33.    // I'm not sure if PREG_GREP_INVERT is fully supported. YMMV.
  34. }
  35.  
  36. foreach($listing as $thisDirItem)
  37. {
  38.    echo "<a href="$thisDirItem">$thisDirItem</a><br>";
  39.    // spit out the list, minus everything we removed above
  40. }
  41.  
  42. ?>
Parsed in 0.012 seconds