Este es el codigo del script:
Código PHP:
<?php
class DIRINFO
{
var $root_dir;
var $root_url;
var $date_format="%d %b %y %H:%M";
var $icon = array(
'default'=>'none.gif',
'File Folder'=>'/icons/dir.gif',
'html'=>'/icons/world1.gif');
var $list_detail = array(
"Name-url"=>"Name",
"Size"=>"Size",
"Type"=>"Type",
"Modified"=>"Modified"
);
var $stat=array( array() );
var $sort=array();
function DIRINFO($root_dir, $root_url, $filter, $icon=NULL, $date="")
{ // initialize class
$this->root_dir = $root_dir;
$this->root_url = $root_url;
$this->filter = $filter;
if ($date != "") $this->date_format = $date;
if ( $icon != NULL)
$this->icon = $icon;
// files
$this->no_item = 0;
$dh = ( is_dir($root_dir) ? opendir($root_dir): FALSE);
foreach ( glob("$root_dir/$filter") as $file_full )
{ $file = basename($file_full);
if ( $file != "." && $file != "..")
{ // set index
$id = $this->no_item;
$this->order[$id] = $id;
$this->no_item ++;
// item info
$item="$root_dir/$file";
//=== Extract File Information
$stat = stat($item);
//=== Determine Name and Name-url
$this->stat[$id]['fname'] = $file;
// determine icon
$this->stat[$id]['ftype'] = filetype($item);
if ( $this->stat[$id]['ftype'] == "dir" )
$this->stat[$id]['Type'] = "File Folder";
else if ( $this->stat[$id]['ftype'] == "file")
$this->stat[$id]['Type'] = substr(strrchr($file, '.'), 1 );
else
$this->stat[$id]['Type'] = "Unknown";
$icon = $this->icon[$this->stat[$id]['Type']];
if ($icon == '')
$icon = $this->icon['default'];
// url
$this->stat[$id]['url']=$this->root_url . "/$file";
// file name
$this->stat[$id]['Name'] =
'<IMG class=dir-icon SRC="'.$icon.'"></IMG> '.$file;
// file name with url link
// $this->stat[$id]['Name-url'] =
// '<A HREF="'.$this->stat[$id]['url'].'">'.
// '<IMG class=dir-icon SRC="'.$icon.'"></IMG> '.
// $file."</A>";
$this->stat[$id]['icon']=
'<A HREF="'.$this->stat[$id]['url'].'">'.
'<IMG class=dir-icon SRC="'.$icon.'"></IMG><BR/>'.
$file."</A>";
//=== Determine Size
$this->stat[$id]['Size'] =
$stat['size']. " Byte";
//=== Determine Attribute
$this->stat[$id]['Attribute'] = $stat['mode'];
$this->stat[$id]['Created'] = strftime($this->date_format, $stat['ctime']);
$this->stat[$id]['Accessed'] = strftime($this->date_format, $stat['atime']);
$this->stat[$id]['Modified'] = strftime($this->date_format, $stat['mtime']);
}
} // if glob
} // end GetFileList
function Sort($sortkey=array('ftype', 'Name'))
{ if ($this->no_item > 0)
{
$this->sort = $sortkey;
usort($this->order, array($this, "DirSort"));
}
}
function DirSort($a, $b)
{ $order=1;
foreach ( $this->sort as $key )
{ if ( $this->stat[$a][$key] < $this->stat[$b][$key])
{ $order = -1;
break;
}
}
return $order;
}
function DisplayIcon($id="", $no_col=11, $attrib=array())
{
if ($attrib==NULL)
$attrib=array('icon'=>'Name', 'Modified'=>'Size');
echo "<TABLE $id>";
$count=$no_col;
if ($this->no_item > 0)
{ for ($id = 0; $id < $this->no_item; $id ++)
{ // Generate new row
if ($count == $no_col)
{ $count = 0;
echo "<TR>";
}
$count ++;
// Print out
echo "<TD>";
$i = $this->order[$id];
foreach ( $attrib as $column=>$desc )
echo "<SPAN class='$column'>".$this->stat[$i][$column]."</SPAN><BR/>";
echo "\n";
} // for $id
} // if no_item > 0
echo "</TABLE>";
}
} // End class
?>