Skip to content

Instantly share code, notes, and snippets.

@devluis
Created December 29, 2013 20:05
Show Gist options
  • Save devluis/8174216 to your computer and use it in GitHub Desktop.
Save devluis/8174216 to your computer and use it in GitHub Desktop.
List images inside folder
<?php
if ($handle = opendir('myFolder')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo $file."<br />";
}
/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment