<?php
// phpls
// This script will list everything in a directory
// store it in an array called $list
// by Min-Hsao Chen minhsao@mintrix.net
// http://www.mintrix.net/projects/
//
// if there are any questions please email me.
// This script is under GNU Public license.
// I will not be responsible for anything that 
// happened because of using this script.
//
// if you are worried about security please review the code before using.
// Once again, if you have any comments or question or simply if you like the
// script please email me and let me know.   
// thanks and have fun.
//
// user mod section
$directory="new";    // the directory you want to list 
$descrbfile="desc.txt";  // the description text file 
                         // in the file use   filename , file description per line
                         
// main program

$location=$directory."/".$descrbfile;
$filearray=file($location);  
$desc=getassocarray($filearray);
$output=getDirList($directory);

// functions
function getDirList ($dirName) {
// This function get the directory list
$list=array();
$d dir($dirName);
while(
$entry $d->read()) {
if (
$entry != "." && $entry != ".." && $entry != "desc.txt") {
array_push($list,$entry);
}
}
$d->close();
return(
$list);
}


function 
getassocarray($oldarray) {
// turns the first value in the array in to the key

foreach ($oldarray as $line) {
  
$parts=explode(",",$line);
  
$key=array_shift($parts);
  
$line=implode(",",$parts);
  
$outarray[$key]=$line;
// end foreach

return($outarray);
}


function 
typeoffile($in){
// this function determines the file type
// feel free to add any file type you wish
// just follow the format
$input=rtrim($in);
switch (
$input) {
  case 
exe:  // extension that ends with exe
      
$output="executable";  // it is a executable file
      
break;    // break
  
case jpg:
      
$output="picture";
      break;
  case 
gif:
      
$output="picture";
      break;
  case 
php :
      
$output="script";
      break;  
  case 
asp:
      
$output="script";
      break;
  case 
txt:
      
$output="text";
      break;
  default:
      
$output=$in;  // if not on the list the extension is just listed.
}
return (
$output);
}


function 
getextension($filename) {
// this function gets the extension
  
$parts=explode(".",$filename);
  
$extension=array_pop($parts);
  return(
$extension);
// end of getextension


?>

<?
echo "<h2>$directory</h2><br>";
?>
<table>
<tr><td><b>Filename</b></td><td><b>Description</b></td><td><b>Filetype</b></td></tr>
<? foreach ($output as $file){ ?>
<tr>
<td><a href="<? echo "$directory/$file"?>"> <? echo "$file"?></td>
<td>
<?
echo "  $desc[$file]  ";
?>
</td>
<td>
<?
  $filetype
=typeoffile(getextension($file)); 
  echo 
"$filetype"
?>
</td>
</tr>
<? ?>
</table>
<small><a href="http://www.mintrix.net/projects/">ls-php</a> .. version 0.001 </small>