Skip to content

Instantly share code, notes, and snippets.

@gr8pathik
Created December 3, 2013 07:30
Show Gist options
  • Save gr8pathik/7765328 to your computer and use it in GitHub Desktop.
Save gr8pathik/7765328 to your computer and use it in GitHub Desktop.
Directory Listing in PHP
<?php
function list_files($dir)
{
if(is_dir($dir))
{
if($handle = opendir($dir))
{
while(($file = readdir($handle)) !== false)
{
if($file != "." &amp;&amp; $file != ".." &amp;&amp; $file != "Thumbs.db"/*pesky windows, images..*/)
{
echo '<a target="_blank" href="'.$dir.$file.'">'.$file.'</a><br>'."\n";
}
}
closedir($handle);
}
}
}
/*
To use:
<?php
list_files("images/");
?>
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment