HOW TO LIST FILES IN A DIRECTORY WITH PHP

By | July 12, 2012
0
0



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;
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *