Wednesday, 11 July 2018

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

0 comments:

Post a Comment