Skip to content

Instantly share code, notes, and snippets.

@ertankayalar
Created June 22, 2013 14:00
Show Gist options
  • Select an option

  • Save ertankayalar/5840965 to your computer and use it in GitHub Desktop.

Select an option

Save ertankayalar/5840965 to your computer and use it in GitHub Desktop.
directory list
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
if ($handle = opendir('/media/book')) {
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\n";
}
/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
}
?>
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
if ($handle = opendir('/media/book/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment