Skip to content

Instantly share code, notes, and snippets.

@rginnow
Created April 26, 2017 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rginnow/e1eda44ed8254cfb1139a806477623a2 to your computer and use it in GitHub Desktop.
Save rginnow/e1eda44ed8254cfb1139a806477623a2 to your computer and use it in GitHub Desktop.
List files in directory using PHP (Linux or Windows)
<?php
// From https://tympanus.net/codrops/2009/09/01/how-to-list-files-in-a-directory-with-php/
$row = exec('ls -ls',$output,$error);
while(list(,$row) = each($output)){
echo $row, "<BR>\n";
}
if($error){
echo "Error : $error<BR>\n";
exit;
}
// Or windows
// $row = exec('dir',$output,$error);
// while(list(,$row) = each($output)){
// echo $row, "<BR>\n";
// }
// if($error){
// echo "Error : $error<BR>\n";
// exit;
// }
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment