Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/03/2007, 14:17
elkronos
 
Fecha de Ingreso: septiembre-2004
Mensajes: 66
Antigüedad: 19 años, 7 meses
Puntos: 0
Re: Necesito mostrar la estructura y archivos de un directorio

No lo he probado pero eso es lo que pude encontrar suerte

<?php
main();

function main(){
//Set Variables
$testDirName = "test_dir";
$fileListArray = array();
$dirListArray = array();

$aDirectory = new DirReader($testDirName);

// Store File List in Array
$fileListArray = $aDirectory->getFileList();
$dirListArray = $aDirectory->getDirList();

echo "<html><body>\n";
echo "<pre>\n";

echo "Reading Directory: ". $aDirectory->getDirPath() ."\n";
echo "Current Directory: ". getcwd() ."\n";

echo "-- Files in Directory --\n";
foreach ($fileListArray as $filename) {
echo "File: $filename\n";
}

echo "\n-- Sub Directories --\n";
foreach ($dirListArray as $filename){
echo "Sub dir: $filename\n";
}
echo "</pre></body></html>\n";
}

class DirReader{
private $dh; # Directory Handle
private $basedir; # Base Directory passed to the object
private $fileNameArray=array();
private $dirNameArray=array();
function __construct($dirname){
$this->basedir = $dirname;
$this->dh = dir($dirname) or die($php_errormsg);
$this->parseDirectory();
}

function parseDirectory(){
$filename = "";
while (false !== ($filename = $this->dh->read())){
$fullpath = $this->basedir . '/' . $filename;
if (is_file($fullpath)){
array_push($this->fileNameArray, $filename);
}else{
array_push($this->dirNameArray, $filename);
}
}
}


// Get all the files in the directory
function getFileList(){
return $this->fileNameArray;
}
// Get all the sub directories in the directory
function getDirList(){
return $this->dirNameArray;
}

function getDirPath(){
return $this->dh->path;
}
}
?>