Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Ordenar Archivos Subidos Por Upload

Estas en el tema de Ordenar Archivos Subidos Por Upload en el foro de PHP en Foros del Web. Buenos días, Tengo un gesto para subir archivos el cual funciona bien, pero al momento de mostarlos lo hace de forma desordenada es decir: 1--- ...
  #1 (permalink)  
Antiguo 06/06/2013, 09:53
 
Fecha de Ingreso: septiembre-2007
Mensajes: 40
Antigüedad: 16 años, 7 meses
Puntos: 0
Ordenar Archivos Subidos Por Upload

Buenos días, Tengo un gesto para subir archivos el cual funciona bien, pero al momento de mostarlos lo hace de forma desordenada es decir:

1--- Archivo 1
100---Archivo
2--- Archivo

Como Podran Ver cuando llega al 100 se coloca detras del numero 1 al igual pasa con el 200 y 300 me gustaria saber como hago para que siga la secuencia

A continuacion el codigo:
Código PHP:
<?php 
$status 
"";

$action = isset($_POST['action']) ? $_POST['action'] : 'archivo'
  if (
$action == "upload" ){
    
// obtenemos los datos del archivo 
    
    
$tamano $_FILES["archivo"]['size'];
    
$tipo $_FILES["archivo"]['type'];
    
$archivo $_FILES["archivo"]['name'];
    
$prefijo $_POST["dato"];
    
    if (
$archivo != "") {
        
// guardamos el archivo a la carpeta files
        
$destino =  "files/".$prefijo."---".$archivo;
        
        
        if (
file_exists("files/" $_FILES['archivo']['tmp_name'])) {
          
$destino=  $_FILES['archivo']['tmp_name'] . " ya existe. ";
        }
        else{
        if (
copy($_FILES['archivo']['tmp_name'],$destino)) {
            
$status "Archivo subido: <b>".$archivo."</b>";
            
        
        } else {
            
$status "Error al subir el archivo";
        }
    
    }
    }

    
 

}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Subir Guiones</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0" align="center" >
  <tr>
    
   
    <td width="413" height="40" align="center"><a href="index.php?menu=Principal"><img src="images/tv_ead.jpg" width="225" height="100" align="absbottom" border="0"> </td>
  
 
  </tr>
  
  
  <table border="0" align="center">
  <tr>
    <td class="text">Por favor seleccione el archivo a subir: <a href="MODELO GUIÓN AUDIOS.docx">Modelo de Guion</a></td>
  </tr>
  <tr>
  
  <form action="upload.php" method="post" enctype="multipart/form-data">
    <td class="text">
      Nro Solicitud
      <input name="dato" type="text" class="casilla" id="dato" size="20"  />
      <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
      <input name="enviar" type="submit" class="boton" id="enviar" value="Subir Guion" />
      <input name="action" type="hidden" value="upload" />      
       
      
      </td>
      
    </form>
  </tr>

  <tr>
    <td class="text" style="color:#990000"><?php echo $status?></td>
  </tr>
 
  <tr>
   
  </tr>
  <tr>
     </table>
    
    <table border="0" align="left">
    <tr>
    <td height="30" class="subtitulo">Listado de Archivos Subidos <img src="images/modif.png" width="50" height="50" align="absbottom" border="0"> </td>
  </tr>
    <td class="infsub">
      
    <?php 
    


    
if ($gestor opendir('files')) {
        echo 
"<ul>";
        while (
false !== ($arch readdir($gestor))) {
          
           
          if (
$arch != "." && $arch != "..") {
             
            
               echo 
"<li><a href=\"files/".$arch."\" class=\"linkli\">".$arch."</a></li>\n";
           }
        }
        
closedir($gestor);
        echo 
"</ul>";
    }
    
?>    </td>
  </tr>
<tr>
</table>
</body>
</html>
  #2 (permalink)  
Antiguo 06/06/2013, 10:04
Avatar de guardarmicorreo  
Fecha de Ingreso: noviembre-2012
Ubicación: Córdoba
Mensajes: 1.153
Antigüedad: 11 años, 5 meses
Puntos: 84
Respuesta: Ordenar Archivos Subidos Por Upload

¿los archivos los muestras cuando ya los subistes al servidor o cuando los estás subiendo?

porque si los muestras cuando ya los subistes el orden depende de la lectura a la base de datos.
  #3 (permalink)  
Antiguo 06/06/2013, 10:09
 
Fecha de Ingreso: septiembre-2007
Mensajes: 40
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Ordenar Archivos Subidos Por Upload

Los Archivos se guardan en una capeta y se muestran despues que se realiza el upload..
  #4 (permalink)  
Antiguo 06/06/2013, 10:17
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Ordenar Archivos Subidos Por Upload

2 opciones
1-leer el directorio y leer la fecha de cada archivo y reorganizar por ella para mostrarla por pantalla
2-Hacer que se guarde el nombre en la base de datos y luego mostrarlo por id
  #5 (permalink)  
Antiguo 06/06/2013, 10:24
 
Fecha de Ingreso: septiembre-2007
Mensajes: 40
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Ordenar Archivos Subidos Por Upload

Segun me codigo me podrias indicar como leer la fecha ya que estan guardados en un directorio de la PC
  #6 (permalink)  
Antiguo 06/06/2013, 10:37
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Ordenar Archivos Subidos Por Upload

Cita:
Iniciado por eprado Ver Mensaje
Segun me codigo me podrias indicar como leer la fecha ya que estan guardados en un directorio de la PC
ok aqui el codigo:

con un pequeño plus:

Código PHP:
<?php 
$status 
"";

$action = isset($_POST['action']) ? $_POST['action'] : 'archivo'
  if (
$action == "upload" ){
    
// obtenemos los datos del archivo 
    
    
$tamano $_FILES["archivo"]['size'];
    
$tipo $_FILES["archivo"]['type'];
    
$archivo $_FILES["archivo"]['name'];
    
$prefijo $_POST["dato"];
    
    if (
$archivo != "") {
        
// guardamos el archivo a la carpeta files
        
$destino =  "files/".$prefijo."---".$archivo;
        
        
        if (
file_exists("files/" $_FILES['archivo']['tmp_name'])) {
          
$destino=  $_FILES['archivo']['tmp_name'] . " ya existe. ";
        }
        else{
        if (
copy($_FILES['archivo']['tmp_name'],$destino)) {
            
$status "Archivo subido: <b>".$archivo."</b>";
            
        
        } else {
            
$status "Error al subir el archivo";
        }
    
    }
    }

    
 

}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Subir Guiones</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0" align="center" >
  <tr>
    
   
    <td width="413" height="40" align="center"><a href="index.php?menu=Principal"><img src="images/tv_ead.jpg" width="225" height="100" align="absbottom" border="0"> </td>
  
 
  </tr>
  
  
  <table border="0" align="center">
  <tr>
    <td class="text">Por favor seleccione el archivo a subir: <a href="MODELO GUIÓN AUDIOS.docx">Modelo de Guion</a></td>
  </tr>
  <tr>
  
  <form action="upload.php" method="post" enctype="multipart/form-data">
    <td class="text">
      Nro Solicitud
      <input name="dato" type="text" class="casilla" id="dato" size="20"  />
      <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
      <input name="enviar" type="submit" class="boton" id="enviar" value="Subir Guion" />
      <input name="action" type="hidden" value="upload" />      
       
      
      </td>
      
    </form>
  </tr>

  <tr>
    <td class="text" style="color:#990000"><?php echo $status?></td>
  </tr>
 
  <tr>
   
  </tr>
  <tr>
     </table>
    
    <table border="0" align="left">
    <tr>
    <td height="30" class="subtitulo">Listado de Archivos Subidos <img src="images/modif.png" width="50" height="50" align="absbottom" border="0"> </td>
  </tr>
    <td class="infsub">
      
    <?php 
function bytestostring($size$precision 0) {
    
$sizes = array('YB''ZB''EB''PB''TB''GB''MB''kB''B');
    
$total count($sizes);

    while(
$total-- && $size 1024$size /= 1024;
    return 
round($size$precision).$sizes[$total];
}
function 
ver_extencion($dato){
$tipo=substr($dato,strrpos($dato,".")+1);
return 
$tipo;
}
function 
leer_dir(){ //Funcion que hace la MAGIA
    
if ($gestor opendir('files')) {
        while (
false !== ($archivo readdir($gestor))) {
            
$ARCH=ver_extencion($archivo);// reviso la extencion por logeneral no se usa
          
if ($arch != "." && $arch != "..") {
            
$Tam=bytestostring(filesize("files/".$archivo));
            
$todo[filemtime("files/".$archivo)]=array($archivo,$Tam);// agrego un array con la fecha del archivo
            
}
        }
    }
        
closedir($gestor);
        
krsort($todo);// reordena los resultados por fecha
    
return $todo;    
}
    
    
$archivos=leer_dir();//REALIZA un arreglo o array
    
?><ul><?
for($i=0$i<count($archivos); $i++){
    
$dato=current($archivos);
    
$arc=$dato[0];
    
$tam=$dato[1];
    
?>
<li><a href="files/<?=$arc?>" class="linkli"><?=$arc?></a> ----  <?=$tam?></li>
    <?
    next
($archivos);
    }
    
?></ul>
</td>
  </tr>
<tr>
</table>
</body>
</html>

dime si funciona.
  #7 (permalink)  
Antiguo 06/06/2013, 11:15
 
Fecha de Ingreso: septiembre-2007
Mensajes: 40
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Ordenar Archivos Subidos Por Upload

Gracias por el codigo funciona perfectamente...


Saludos...
  #8 (permalink)  
Antiguo 06/06/2013, 11:18
 
Fecha de Ingreso: septiembre-2007
Mensajes: 40
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Ordenar Archivos Subidos Por Upload

Auque no me habia fijado me aparecen en mi lista primero un punto y despues dos puntos que seran ?

.
..
  #9 (permalink)  
Antiguo 06/06/2013, 11:28
Avatar de wizanchez  
Fecha de Ingreso: junio-2013
Ubicación: bogota
Mensajes: 120
Antigüedad: 10 años, 10 meses
Puntos: 6
Respuesta: Ordenar Archivos Subidos Por Upload

- . la carpeta activa
- .. ir un arbol mas arriba
__________________
---------
cubesoftechnology.com
Wizanchez,,
  #10 (permalink)  
Antiguo 06/06/2013, 11:54
 
Fecha de Ingreso: septiembre-2007
Mensajes: 40
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Ordenar Archivos Subidos Por Upload

ok Gracias .....

Etiquetas: html, upload
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 14:37.