Foros del Web » Programando para Internet » PHP »

leer el contenido de una carpeta...

Estas en el tema de leer el contenido de una carpeta... en el foro de PHP en Foros del Web. Hola a todos, antes que nada les quiero decir que he buscado, necesito saber como tengo que hacer para listar el contenido de archivos de ...
  #1 (permalink)  
Antiguo 09/08/2005, 14:11
Avatar de turco_7  
Fecha de Ingreso: diciembre-2003
Ubicación: Córdoba, Argentina
Mensajes: 1.044
Antigüedad: 20 años, 4 meses
Puntos: 19
leer el contenido de una carpeta...

Hola a todos, antes que nada les quiero decir que he buscado, necesito saber como tengo que hacer para listar el contenido de archivos de una carptea. osea lo que necesito es listar para saber cuales son los archivos que contiene ... saludos ..
__________________
Mi Blog http://turco7.blogspot.com
Usuario Linux : 404289
Mi última página: http://www.digitalservicecba.com.ar - Reparacion de camaras digitales!

Última edición por turco_7; 09/08/2005 a las 14:51
  #2 (permalink)  
Antiguo 09/08/2005, 15:28
Avatar de stock  
Fecha de Ingreso: junio-2004
Ubicación: Monterrey NL
Mensajes: 2.390
Antigüedad: 19 años, 9 meses
Puntos: 53
aqui te pongo un ejemplo:

Código PHP:
<html>
<head>
    <title>Crysfel Storage Page</title>
    <link href="http://pulso.um.edu.mx/~crysfel/icons/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
  
echo "<h1>".getcwd()."</h1>";
  echo 
"\n<h2><a href=\"..\">Subir nivel</a></h2>\n<table border=\"0\" align=\"center\">";
  
$dirr=opendir('.');
  
$i=1;
  while (
$file=readdir($dirr)) {

    if (
$file!='..' && $file!='.' && $file!='' && $file!='index.php'
    {
        if(
$i==1)
            echo 
"\n\t<tr>";
        if (
is_dir($file)) {
            echo 
"\n\t\t<td width=\"200\"><a href=\"".$file."\"><img src=\"http://pulso.um.edu.mx/~crysfel/icons/".getIcon()."\" border=0 alt=\"".size_archivo($file)."\"></a><br><a href=\"".$file."\">".$file."</a></td>";
        } else {
            echo 
"\n\t\t<td width=\"200\"><a href=\"".$file."\"><img src=\"http://pulso.um.edu.mx/~crysfel/icons/".getIcon($file)."\" border=0 alt=\"".size_archivo($file)."\"></a><br><a href=\"".$file."\">".$file."</a></td>";
        }
        if(
$i==3){
            echo 
"</tr>";
            
$i=0;
        }
        
$i++;
    }
  }
  
closedir($dirr);
  if(
$i==2)
      echo 
"<td width=\"200\">&nbsp;</td><td width=\"200\">&nbsp;</td></tr>";
  if(
$i==3)
      echo 
"<td width=\"200\">&nbsp;</td></tr>";
  echo 
"</table>";
  
//**************************
  //        FUNCIONES
  //**************************
    
function size_archivo($file) {
           
$size filesize($file);
            
$sizes = Array('Bytes''Kb''Mb''Gb''Tb''Pb''Eb');
            
$ext $sizes[0];
            for (
$i=1; (($i count($sizes)) && ($size >= 1024)); $i++) {
              
$size $size 1024;
              
$ext  $sizes[$i];
           }
           return 
round($size2)." ".$ext;
     }
    
    function 
getIcon($archivo "1"){
        if(
$archivo!=1)
            
$typeFile substr($archivo,strlen($archivo)-3);
        else
            
$typeFile "carpeta";
        
$typeFile strtolower($typeFile);
        switch(
$typeFile){
            case 
"carpeta"    :    $icon "folder.png"; break;
            case 
"jpg"        :    $icon "jpg.png"; break;
            case 
"gif"        :    $icon "gif.png"; break;
            case 
"png"        :    $icon "png.png"; break;
            case 
"pdf"        :    $icon "pdf.png"; break;
            case 
"htm"        :    $icon "html.png"; break;
            case 
"tml"        :    $icon "html.png"; break;
            case 
"mp3"        :    $icon "mp3.png"; break;
            case 
"exe"        :    $icon "exec.png"; break;
            default            :     
$icon "file.png"; break;
        }
        return 
$icon;
    }
?>
Donde pongas ese archivo, te va a mostrar el contenido de la carpeta donde se encuentre este, te pone unos icons dependiendo del tipo de archivo y te muestra el peso de cada fichero

have funn
  #3 (permalink)  
Antiguo 09/08/2005, 23:02
Avatar de turco_7  
Fecha de Ingreso: diciembre-2003
Ubicación: Córdoba, Argentina
Mensajes: 1.044
Antigüedad: 20 años, 4 meses
Puntos: 19
Muchas grracias stock lo voy he probado y funciona de 100 :D gracias nuevamente!!!!
__________________
Mi Blog http://turco7.blogspot.com
Usuario Linux : 404289
Mi última página: http://www.digitalservicecba.com.ar - Reparacion de camaras digitales!
  #4 (permalink)  
Antiguo 28/11/2005, 15:56
Avatar de RoQ
RoQ
 
Fecha de Ingreso: abril-2005
Mensajes: 771
Antigüedad: 19 años
Puntos: 0
Hola, gracias por el script estaba buscando algo asi, pero ¿crees que se podria hacer que solo muestre las imagenes (jpg gif png) y sus dimensiones? algo asi:
Nombre | acho | alto
imagen1.jpg | 450 | 200
imagen2.jpg | 720 | 351

Gracias
  #5 (permalink)  
Antiguo 28/11/2005, 16:10
Avatar de Seppo  
Fecha de Ingreso: marzo-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.284
Antigüedad: 19 años, 1 mes
Puntos: 17
Código PHP:
<html>
<head>
    <title>Crysfel Storage Page</title>
    <link href="http://pulso.um.edu.mx/~crysfel/icons/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
  
echo "<h1>".getcwd()."</h1>";
  echo 
"\n<h2><a href=\"..\">Subir nivel</a></h2>\n<table border=\"0\" align=\"center\">";
  
$dirr=opendir('.');
  
$i=1;
  echo 
"<tr><td width=\"200\">Archivo</td><td width=\"200\">Ancho</td><td width=\"200\">Alto</td>";
  while (
$file=readdir($dirr)) {

    if (
$file!='..' && $file!='.' && $file!='' && $file!='index.php')
    {
//        if($i==1)
            
echo "\n\t<tr>";
        if (
is_dir($file)) {
/*            echo "\n\t\t<td><a href=\"".$file."\"><img src=\"http://pulso.um.edu.mx/~crysfel/icons/".getIcon()."\" border=0

alt="".size_archivo($file)."\"></a><br><a href=\"".$file."\">".$file."</a></td>";*/
        
} elseif (substr($file,-4) == ".jpg" OR substr($file,-4) == ".gif" OR substr($file,-4) == ".png") {
            
$size getimagesize($file);
            echo 
"\n\t\t<td><a href=\"".$file."\"><img src=\"http://pulso.um.edu.mx/~crysfel/icons/".getIcon($file)."\" border=0

alt=\""
.size_archivo($file)."\"></a><br><a href=\"".$file."\">".$file."</a></td><td>".$size[0]."</td><td>".$size[1]."</td>";
        }
//        if($i==3){
            
echo "</tr>";
            
$i=0;
//        }
        
$i++;
    }
  }
  
closedir($dirr);
  if(
$i==2)
      echo 
"<td width=\"200\">&nbsp;</td><td width=\"200\">&nbsp;</td></tr>";
  if(
$i==3)
      echo 
"<td width=\"200\">&nbsp;</td></tr>";
  echo 
"</table>";
  
//**************************
  //        FUNCIONES
  //**************************
    
function size_archivo($file) {
           
$size filesize($file);
            
$sizes = Array('Bytes''Kb''Mb''Gb''Tb''Pb''Eb');
            
$ext $sizes[0];
            for (
$i=1; (($i count($sizes)) && ($size >= 1024)); $i++) {
              
$size $size 1024;
              
$ext  $sizes[$i];
           }
           return 
round($size2)." ".$ext;
    }
    
    function 
getIcon($archivo "1"){
        if(
$archivo!=1)
            
$typeFile substr($archivo,strlen($archivo)-3);
        else
            
$typeFile "carpeta";
        
$typeFile strtolower($typeFile);
        switch(
$typeFile){
            case 
"carpeta"    :    $icon "folder.png"; break;
            case 
"jpg"        :    $icon "jpg.png"; break;
            case 
"gif"        :    $icon "gif.png"; break;
            case 
"png"        :    $icon "png.png"; break;
            case 
"pdf"        :    $icon "pdf.png"; break;
            case 
"htm"        :    $icon "html.png"; break;
            case 
"tml"        :    $icon "html.png"; break;
            case 
"mp3"        :    $icon "mp3.png"; break;
            case 
"exe"        :    $icon "exec.png"; break;
            default            :     
$icon "file.png"; break;
        }
        return 
$icon;
    }
?>

Última edición por Seppo; 28/11/2005 a las 17:13
  #6 (permalink)  
Antiguo 28/11/2005, 16:58
Avatar de RoQ
RoQ
 
Fecha de Ingreso: abril-2005
Mensajes: 771
Antigüedad: 19 años
Puntos: 0
hola, gracias lo puse dentro de una carpeta llena de imagenes y me boto este error
Cita:
Parse error: parse error in c:\...\index.php on line 22
instale Easyphp en mi maquina para hacer mis pruebas con php, pero ahora lo pruebo en un servidor
  #7 (permalink)  
Antiguo 28/11/2005, 17:01
Avatar de Seppo  
Fecha de Ingreso: marzo-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.284
Antigüedad: 19 años, 1 mes
Puntos: 17
mmm... andá al php.ini y fijate si tenés una linea
;extension=php_gd2.dll
sacale el ; y reiniciá el Apache...
  #8 (permalink)  
Antiguo 28/11/2005, 17:08
Avatar de RoQ
RoQ
 
Fecha de Ingreso: abril-2005
Mensajes: 771
Antigüedad: 19 años
Puntos: 0
Cita:
Iniciado por Seppo
mmm... andá al php.ini y fijate si tenés una linea
;extension=php_gd2.dll
sacale el ; y reiniciá el Apache...
Gracias por volver a contestar, revise el php.ini y encontre la linea que me dices pero ya esta sin el ;, e igual me bota el error, probe subirlo a un servidor y me boto un error:
Cita:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
  #9 (permalink)  
Antiguo 28/11/2005, 17:14
Avatar de Seppo  
Fecha de Ingreso: marzo-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.284
Antigüedad: 19 años, 1 mes
Puntos: 17
Fijate que edité el mensaje #5 porque tuve un error al copiar y pegar mi código... Si no anda ahora, lloro.
  #10 (permalink)  
Antiguo 28/11/2005, 17:31
Avatar de RoQ
RoQ
 
Fecha de Ingreso: abril-2005
Mensajes: 771
Antigüedad: 19 años
Puntos: 0
Funciona perfecto!, gracias maestro!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:58.