Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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