How to list files in a directory with PHP

Here’s a simple way to execute the windows dir or the linux ls in PHP Windows: <?php $row = exec('dir',$output,$error); while(list(,$row) = each($output)){ echo $row, "<BR>\n"; } if($error){ echo "Error : $error<BR>\n"; exit; } ?> Linux: <?php $row = exec('ls -ls',$output,$error); while(list(,$row) = each($output)){ echo $row, "<BR>\n"; } if($error){ echo "Error : $error<BR>\n"; exit; } […]

Here’s a simple way to execute the windows dir or the linux ls in PHP

Windows:

<?php
$row = exec('dir',$output,$error);
while(list(,$row) = each($output)){
echo $row, "<BR>\n";
}
if($error){
echo "Error : $error<BR>\n";
exit;
}
?>

Linux:

<?php
$row = exec('ls -ls',$output,$error);
while(list(,$row) = each($output)){
echo $row, "<BR>\n";
}
if($error){
echo "Error : $error<BR>\n";
exit;
}
?>
Previous:
Next:

Tagged with:

Cody loves jQuery - he puts the magic into every web application. He is crazy about Curry dishes.

View all contributions by

Website: http://tympanus.net/codrops/author/cody/

Related Articles

Feedback 2

Comments are closed.
  1. Pingback: PHP: How to list files of a directory

  2. 1

    Alem de executar em diretórios ele também server para executar comandos CMD, valeu pelo código obrigado!

Comments are closed.