Skip to content

Instantly share code, notes, and snippets.

@philsinatra
Last active December 18, 2015 19:19
Show Gist options
  • Save philsinatra/5831744 to your computer and use it in GitHub Desktop.
Save philsinatra/5831744 to your computer and use it in GitHub Desktop.
PHP sample showing how to output the files in a directory.
<?php
// define the directory location
$dir = 'directoryname';
// open the directory
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
// ignore invisible files
if ($entry != '.' && $entry != '..' && $entry != '.DS_Store') {
// build a list of the contents of the directory
echo '<li>';
echo '<a href="' . $dir . $entry . '" target="_blank">';
echo substr($entry, 0, -5);
echo '</a>';
echo '</li>';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment