Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: None | Size: 0.39 KB | Hits: 71 | Expires: Never
Copy text to clipboard
  1. if ($handle = opendir('/path/to/files')) {
  2.     echo "Directory handle: $handle\n";
  3.     echo "Files:\n";
  4.  
  5.     /* This is the correct way to loop over the directory. */
  6.     while (false !== ($file = readdir($handle))) {
  7.         echo "$file\n";
  8.     }
  9.  
  10.     /* This is the WRONG way to loop over the directory. */
  11.     while ($file = readdir($handle)) {
  12.         echo "$file\n";
  13.     }
  14.  
  15.     closedir($handle);
  16. }