Inventando con el código, esto es lo que he podido hacer adicional. En este código le estoy indicando que lea solamente los archivos pdf, ustedes lo pueden colocar a la manera que quieran
index.php o
index.html
Código HTML:
Ver original<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<frameset cols="20%,80%">
<frame src="directories.php" />
<frame src="blank.php" name="content" />
</frameset>
directories.php
Código PHP:
Ver original<?php require_once 'class.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="script.js"></script>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<?php
$dirStructure = new DirStructure
(array('pdf'));
/**
* The next line you can specified the directory that you want to check,
* if not specified it will check the current directory
*/
echo $dirStructure->getFile($dirStructure->setFile($dirStructure->path('docs')));
?>
<div id="tree_notification">Cargando...</div>
</body>
</html>
class.php
Código PHP:
Ver original<?php
class DirStructure{
/**
* Avoid using .. /, so you can not go back
* Default false
*/
private $_safeMode = false;
/**
* Hide all directories that do not have any files,
* even if there are other directories that are empty
* Default true
*/
private $_hideEmptyDir = true;
/**
* Show only this extentions. Format: mime type
* application/pdf PDF
* application/zip DOCX|XLSX|PPTX|...
* application/octet-stream ZIP
* application/x-rar RAR
* text/x-php PHP
* text/html HTML/HTM
* application/x-empty (empty files)
*
* Example of how it will be set:
* $_fInfoExt = array('application/pdf', 'application/zip', 'text/x-php');
*
* Leave blank if you want to display all
* $_fInfoExt = array();
*
* @param array $array
*/
private $_realExt = array( 'pdf' => 'application/pdf',
'docx' => 'application/zip',
'xlsx' => 'application/zip',
'pptx' => 'application/zip',
'zip' => 'application/octet-stream',
'rar' => 'application/x-rar',
'php' => 'text/x-php',
'html' => 'text/html',
'empty files' => 'application/x-empty',
);
private $_fInfoExt = array();
public function __construct
(array $array = array()){ foreach($array as $value){
? $this->_realExt[$value]
: $value;
}
}
/**
* Set path for current directory so this scripts works if include in another php file
*
* @param string $dir
* @return string
*/
public function path($dir){
if($this->_safeMode
){ $dir = str_replace('../', '', $dir); } return realpath(__DIR__
. DIRECTORY_SEPARATOR . $dir); }
/**
* Check for real mime extention
*
* @param string $fileUrl Set file to check
* @return string
*/
private function _whatMimeExt($fileUrl = null){
if(empty($fileUrl)){ return; }
return $mimeExtention;
}
/**
* Check if is real extention
*
* @param string $fileUrl Set file to check
* @param array $ext Extention(s) to check. Format: Mime type
* @return bool
*/
private function _realExtFile
($fileUrl, array $ext = array()){ if(empty($ext)){ return false; }
foreach($ext as $e){
if(is_file($fileUrl) && $this->_whatMimeExt
($fileUrl) != $e){ return true; } }
return false;
}
/**
* Get the size of directory. If $_fInfoExt is specified, only get size of directory that has what was indicated.
*
* @param string $dir Directory name
* @return integer
*/
private function _dirSize($dir){
$size = 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $file){
if($this->_realExtFile
(realPath($file->getPathname()), $this->_fInfoExt
)){ continue; } $size+=$file->getSize();
}
return $size;
}
/**
* Set array with the structure of directories and files
*
* @param string $root
* @param int $n
* @return array
*/
public function setFile($root, $n = 0){
$n++;
foreach(glob($root . DIRECTORY_SEPARATOR . '*') as $file){ /**
* Check if dir is empty, do not display and if is
*/
if($this->_hideEmptyDir
&& is_dir($file) && $this->_dirSize
($file) == 0){ continue; }
/**
* Set info of file
*/
/**
* Check if dir name is only number(s), append a space
* to the end of the name to mantain the key when using array_merge.
*/
? $f['basename'] . ' '
: $f['basename'];
'real_path' => realpath($f['dirname'] . DIRECTORY_SEPARATOR . $f['basename']), 'n_array' => $n,
'files_in_dir' => $this->setFile($file, $n)
);
}
else{
$onlyFiles[$f['basename']] = array( 'real_path' => realpath($f['dirname'] . DIRECTORY_SEPARATOR . $f['basename']), 'n_array' => $n,
);
}
}
}
/**
* Organize array given of setFile()
*
* @param array $files
* @param string $class Show or hide directory info, values: show|hide Default: show (for firsts directories)
* @return string
*/
public function getFile($files, $class='show'){
$customFile = '';
foreach($files as $key => $file){
if($this->_realExtFile($file['real_path'], $this->_fInfoExt)){ continue; }
if(is_array($file) && $key != 'pathInfo'){ if($key != 'files_in_dir'){
/**
* Check if is directory or file and if is a file you can add more mime extentions
* for more info about mime extention check the method setFInfoExt()
*/
switch($this->_whatMimeExt($file['real_path'])){
case 'directory':
$img = '<img src="images/dir.png" width="20" height="20" alt="' . trim($key) . '" title="' . trim($key) . '" />'; break;
case 'application/pdf':
$img = '<img src="images/pdf.png" width="20" height="20" alt="' . trim($key) . '" title="' . trim($key) . '" />'; break;
default:
$img = '<img src="images/file.png" width="14" height="20" alt="' . trim($key) . '" title="' . trim($key) . '" />'; }
$tab = str_repeat(" ", $file['n_array']); $link = (empty($file['http_path']) ?
'<a href="javascript: void(0);" onclick="hideUnhideMenu(this)" >' . $img . trim($key) . '</a>' : '<a href="' . $file['http_path'] . '" target="content" onclick="'
. 'hideUnhideExtras(\'tree_notification\');'
. ' setTimeout(\'hideUnhideExtras(\\\'tree_notification\\\')\', 1500);'
. '">' . $img . ' ' . trim($key) . '</a>' );
$customFile .= $tab . ' ' . $link . '<br />';
}
if(!empty($file['files_in_dir'])){ $customFile .= $this->getFile($file['files_in_dir'], 'hide');
}
}
}
return '<div class="tree_' . $class . '">' . $customFile . '</div>';
}
}
style.css
Código CSS:
Ver original* { padding: 0; margin: 0; }
html, body{ width: 100%; height: 100%; }
body {
background: #C3C3C3;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
color: #666666;
}
a{
color: #369;
text-decoration: none;
font-weight: bold;
}
a:hover{ color: #900; }
img{ border: none; }
/*tree*/
.tree_hide{ display: none; }
.tree_show{ display: block; }
#tree_notification{
background-color: #6886ac;
padding: 4px 5px 5px 5px;
position: absolute;
top: 0;
right: 0;
color: #fff;
font-size: 14px;
display: none;
}
script.js
Código Javascript
:
Ver originalfunction hideUnhideMenu(obj){
obj = obj.nextSibling;
while(obj.nodeName != 'DIV'){
obj = obj.nextSibling
}
var thisElement = obj.style;
if(thisElement.display == 'block'){ thisElement.display = 'none'; }
else{ thisElement.display = 'block'; }
}
function hideUnhideExtras(id){
var thisElement = document.getElementById(id).style;
if(thisElement.display == 'block'){ thisElement.display = 'none'; }
else{ thisElement.display = 'block'; }
}
blank.php o
blank.html es un archivo vacio, para evitar errores en los frames. Crean un directorio llamado
images y colocan las siguientes imagenes
dir.png
pdf.png
file.png
Edito: Necesitan tener activa la extensión
php_fileinfo Nota: 12-24-2010 - se añadió la variable $safe_mode, sugerida por
miktrv.
12-28-2010 - se cambió el nombre de la variable $safe_mode a $_safeMode y se creó la variable $_hideEmptyDir. Se modificó el código para que en el construct se indicara las extensiones a mostrar