Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/06/2008, 05:54
chicamala
 
Fecha de Ingreso: junio-2008
Mensajes: 24
Antigüedad: 16 años, 9 meses
Puntos: 0
Mensaje Leer multiples carpetas con opendir()

Hola, que tal? , podrá alguien ayudarme? , realmente he buscado y buscado la solución a este problema tanto en inglés como en español y nada...

He estado tratando de leer la info de unas subcarpetas de una carpeta llamada "panel" que a la vez (panel) es la subcarpeta de la carpeta donde tengo el archivo php, me lo hace muy bien si utilizo las funciones solo una vez para una misma carpeta pero no cuando quiero leer las demás para incluir toda la info en una misma página.

Para esto estoy usando opendir(), readdir() y closedir() entre otras funciones para emular un tipo AJAX (pues porque no sé usar ajax y realmente lo único que quiero es meter mis archivos en las carpetas y listo sin necesidad de usar bases de datos), el problema está en que al llamar a las funciones tabla() y ulactual() más de una vez (con diferentes variables de entrada) entonces no me hace la leida de otras carpetas que no sean la primera que especifiqué en las funciones.
Disculpen si incluyo de una vez el código de toda la página, es que... realmente no sé si alomejor es algo que estoy haciendo mal, más alla del codigo php (talvez de paso le sirve a alguien :p):

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
    *{border:0; margin:0 auto; text-align:center;}
    body { background:#000 url('img/panel_osr.jpg') no-repeat center top; padding-top:50px;
    }
    body,td,th { color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
    .main{ width:700px; display:table; }
    a:link { color:#FF0000; }
    a:visited { color: #FF0000; }
    a:hover { color: #CC0000; }
    a:active { color: #FF0000; }
    .fs10red{ color:#ff0000; }
    .fs10, .fs10red{ font-size:10px;}
    .fl1{ width:40px; height:40px; }
    .fl1, .fl2{ line-height:40px; min-height:40px; float:left;  }
    .mt6{ margin-top:6px; }
    .border{ border:solid 1px #CCCCCC; min-height:40px; display:table; margin-bottom:5px; width:100%; }
    div#iden, div#iden_a { width:100%; height:auto; min-height:150px; line-height:normal; margin-bottom:10px; display:none; clear:both; }
-->
</style>
<script type="text/javascript">
function mostrar( whichLayer )
{  
    var elem, vis;  
    if( document.getElementById ) // this is the way the standards work    
    elem = document.getElementById( whichLayer );  else if( document.all ) // this is the way old msie versions work      
    elem = document.all[whichLayer];  else if( document.layers ) // this is the way nn4 works    
    elem = document.layers[whichLayer];  vis = elem.style;  
    // if the style.display value is blank we try to figure it out here  
    if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
    vis.display = (vis.display==''||vis.display=='block')?'none':'block';

}
</script>
</head>

<body>
<?
function ulactual($direc$archivo){
            
$mes[0]="-"
            
$mes[1]="enero"
            
$mes[2]="febrero"
            
$mes[3]="marzo"
            
$mes[4]="abril"
            
$mes[5]="mayo"
            
$mes[6]="junio"
            
$mes[7]="julio"
            
$mes[8]="agosto";
            
$mes[9]="septiembre";
            
$mes[10]="octubre";
            
$mes[11]="noviembre";
            
$mes[12]="diciembre";

            
$dia[0]="Dom.";
            
$dia[1]="Lun.";
            
$dia[2]="Mar.";
            
$dia[3]="Mi&eacute;.";
            
$dia[4]="Jue.";
            
$dia[5]="Vie.";
            
$dia[6]="S&aacute;b.";

            
$gisett=(int)date("w"filemtime($direc.$archivo));
            
$mesnum=(int)date("m"filemtime($direc.$archivo));

            echo 
$dia[$gisett]." ".date("d"filemtime($direc.$archivo))."/".$mes[$mesnum]."/".date("Y"filemtime($direc.$archivo));
            }

function 
ByteSize($bytes)  
                { 
                
$size $bytes 1024
                if(
$size 1024
                    { 
                    
$size number_format($size2); 
                    
$size .= ' KB'
                    }  
                else  
                    { 
                    if(
$size 1024 1024)  
                        { 
                        
$size number_format($size 10242); 
                        
$size .= ' MB'
                        }  
                    else if (
$size 1024 1024 1024)   
                        { 
                        
$size number_format($size 1024 10242); 
                        
$size .= ' GB'
                        }  
                    } 
                return 
$size
                }
                
function 
tabla($carpeta){                                
            
// This is the directory to list files for.
            
$theDirectory  $carpeta;
            
//Cuenta el no. de archivos en un directorio
            
$max count(glob($theDirectory '*.*'));
            
            
            function 
compare($a,$b) {
            return 
$b[1]-$a[1];
            }
            
$files=Array();
            
$f=opendir($theDirectory);
            while ((
$file=readdir($f))!==false) {
            if(
$file!="." && $file!=".." && is_file("$theDirectory/$file")) {
            
$files[]=Array($file,filemtime("$theDirectory/$file"));
            }
            }
            
closedir($f);
            
usort($files,"compare");
            
$m=min($max,count($files));
            echo 
"<table cellspacing='5' cellpadding='2'><tr><td><b>Nombre</b></td><td><b>Tama&ntilde;o</b></td><td><b>Fecha</b></td></tr>";
            for (
$i=0;$i<$m;$i++) {
            
$filename $files[$i][0];
            echo 
"<tr><td><a href='download.php?file=
"
.$theDirectory.$filename."'>" $filename "</a></td>";
                        echo 
"<td align='right' width='100'>";                        
                        
$size filesize($theDirectory.$filename);
                        echo 
ByteSize($size);

                        echo 
"</td><td>";
                            
ulactual($theDirectory.$filename);                              
                        echo 
"</td></tr>";
            
            }
            echo 
"<tr><td colspan='3' height='30'><span class='fs10'><img src='img/download.gif' alt='download' />Click normal sobre los links para descargar archivo.</span></td></tr>";
            echo 
"</table>";
}

function 
actual($folder){
            
// This is the directory to list files for.
            
$Directory  $folder;
            
//Cuenta el no. de archivos en un directorio
            
$maxi count(glob($Directory '*.*'));            
            
            function 
comp($c,$d) {
                return 
$d[1]-$c[1];
            }
            
$filesi=Array();
            
$f=opendir($Directory);
            while ((
$file=readdir($f))!==false) {
                if(
$file!="." && $file!=".." && is_file("$Directory/$file")) {
                    
$filesi[]=Array($file,filemtime("$Directory/$file"));
                }
            }
            
closedir($f);
            
usort($filesi,"comp");
            
$m=min($maxi,count($filesi));
            
$filename $filesi[1][0];        
            
ulactual($Directory.$filename);
}

?>

<div class="main">
<B>PANEL DE ACCESO A SERVICIOS DE OSR</B><br /><br />
    <div class="border">
        <div>
            <div class="fl1"><div class="mt6"><a href="http://members.ipower.com/mail/index.bml?m=1"><img src="img/correo.gif" alt="correo" width="31" height="24" /></a></div></div>
            <div class="fl2"><a href="http://members.ipower.com/mail/index.bml?m=1"><b>Mail</b></a> En 'E-mail address' se pone tu direcci&oacute;n completa de correo de OSR.</div>
        </div>
    </div>
    
    <div class="border">
        <div>
            <div class="fl1"><div class="mt6"><img src="img/identificativos.gif" alt="identificativos" /></div></div>
            <div class="fl2"><a href="javascript:mostrar('iden');"><b>ID´s</b></a> Mensajes institucionales sobre OSR nombre/concepto. <span class="fs10red">Modificado: <b><? actual("panel/osr_grab_ident/"); ?></b></span></div>
        </div>
        <div id="iden">
            <? tabla("panel/osr_grab_ident/"); ?>
        </div>
    </div>
    
        
    <div class="border">
        <div>
            <div class="fl1"><div class="mt6"><img src="img/promos.gif" alt="Promocionales" /></div></div>
            <div class="fl2"><a href="javascript:mostrar('iden_a');"><b>Promos</b></a> Promocionales de los programas, entrevistas, especiales, etc. <span class="fs10red">Modificado: <b><? actual("panel/osr_grab_promos/"); ?></b></span></div>
        </div>
        <div id="iden_a">
            <? tabla("panel/osr_grab_promos/"); ?>
        </div>
    </div>
        
</div>

</body>
</html>
Les enseñaría las páginas donde tengo trabajando esto pero al parecer no me permiten poner links.


De antemano muchas gracias a quien me conteste (si me contestan ), realmente sería un gran alivio conseguir un poco de ayuda.


Atte. Adriana

Última edición por jam1138; 08/06/2008 a las 13:21