Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/05/2007, 18:47
Avatar de DeeR
DeeR
 
Fecha de Ingreso: diciembre-2003
Ubicación: Santiago
Mensajes: 520
Antigüedad: 20 años, 4 meses
Puntos: 17
Re: Upload Multiple de Arhcivos

Bueno cualquier tutorial de PHP habla el tema de upload de ficheros ...

bueno aqui te tengo un mini script, que mueve todo los archivos que recibe a un directorio, y el pone el mismo nombre pero le agrega 3 caracteres al azar.

Código PHP:
<?

 
// Mueve Todo los Archivos que Recibe
 // by deerme.org
function rand_string($len$chars 'qwertyuiopasdfghjklzxcvbnm1234567890')
{
   
$string '';
   for (
$i 0$i $len$i++)
   {
       
$pos rand(0strlen($chars)-1);
       
$string .= $chars{$pos};
   }
   return 
$string;
}


$directorio $_SERVER['DOCUMENT_ROOT'].'/upload/imagenes/';
$url 'http://pictures.chileantiques.com/upload/imagenes/';
 
foreach (  
$HTTP_POST_FILES as $valor  )
{
     
$rand rand_string(3);
     
     if ( 
$valor['name'] != "" )
     {
     
         if (
move_uploaded_file($valor['tmp_name'],$directorio.$rand.$valor['name']));
         {
               echo 
$url.$rand.$valor['name'].'<br>';
        }
    }
}




?>
Y el form es el mas basico ... mira
Código HTML:
<!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>Documento sin t&iacute;tulo</title>
</head>

<body>
<form action="subir.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <p>
    <label>
    <input type="file" name="file" />
    </label>
  </p>
  <p>
    <label>
    <input type="file" name="file2" />
    </label>
  </p>
  <p>
    <label>
    <input type="file" name="file3" />
    </label>
  </p>
  <p>
    <label>
    <input type="file" name="file4" />
    </label>
  </p>
  <p>
    <label>
    <input type="file" name="file5" />
    </label>
  </p>
  <p>
    <label>
    <input type="file" name="file6" />
    </label>
  </p>
  <p>&nbsp;</p>
  <p>
    <label>
    <input type="submit" name="Submit" value="Enviar" />
    </label>
  </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html> 
Ahora si al sitio, le quieres agregar una funcion que agrege cada vez mas nuevos input para subir archivos, lo puedes hacer con javascript directamente o usar ajax.

Mas que nada son ejemplos, y hay tu ves ciertos parametros de seguridad (como comprobar una cookie o variable de session antes de mover los archivos, solo mover archivos de imagenes, etc ...)

Saludos