Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/04/2008, 10:14
Avatar de Wakkos
Wakkos
Colaborador
 
Fecha de Ingreso: octubre-2001
Ubicación: (cerca)
Mensajes: 1.795
Antigüedad: 22 años, 7 meses
Puntos: 59
Subir varias imágenes + thumbnails

Hola! tengo un script para subir muchas imágenes. Es un coñazo y el problema soy yo que no entiendo los arrays y me cuesta mazo trabajarlos.

Tengo un formulario con
Código:
<FORM name=globe method=POST ACTION="upload.php" enctype=multipart/form-data>
<input type=file name=img1 size=30><br>
<input type=file name=img2 size=30><br>
<input type=file name=img3 size=30><br>
<input type=file name=img4 size=30><br>

<INPUT TYPE="submit" NAME="accion" VALUE="Enviar">
Luego tengo este script para subir y crear thumbnails:
Código PHP:
//Subir primera imagen
srand (time());
$tempo rand (100000000999999999);



    
    
//Chequea el tamano de la imagen
if (($sizelim == "yes") && ($img1_size $size)) {
$log1 .= "Imagen 1 es muy grande<br>";

} else {

//borra espacios en blanco y lo 'minisculiza'
$img1_name strtolower($img1_name);
$img1_name ereg_replace" """$img1_name);

//Revisa si el archivo es una imagen
if (($img1_type == $cert1) or ($img1_type == $cert2)) {
@
copy($img1"$temporal/$img1_name") or $log .= "No se pudo copiar la imagen 1 al servidor, aseg&uacute;rate que es una imagen .JPG<br>";
rename ("$temporal/$img1_name""$abpath/$tempo$img1_name");
if (
file_exists("$abpath/$tempo$img1_name")) {



    
    

$first=ImageCreateFromJPEG("$abpath/$tempo$img1_name") or die("No pudo abrir la imagen");

// Tamaño del Thumbanil (de la imagen a generar ..) 
    
$picsize 150
     
    
// Se obtienen los datos del ancho y alto de la imagen. 
    
$new_w imagesx($first); 
    
$new_h imagesy($first); 

    
// Se calcula la relación alto/ancho 
    
$aspect_ratio $new_h $new_w
     
    
// Se ajusta al nuevo tamaño 
    
$new_w $picsize
    
$new_h abs($new_w $aspect_ratio);
 
$second=ImageCreateTrueColor($new_w,$new_h) or die("No pudo crear la imagen"); 
ImageCopyResized($second,$first,0,0,0,0,$new_w,$new_h,imagesx($first),imagesy($first)) or die("coudln't resize image"); 
ImageJPEG($second,"thumb/$tempo$img1_name") or die("couldn't save image"); 
//crea el thumbnail (usando libreria GD de PHP)

 

$log1 .= "ok";



}
} else {

$log1 .= "Campo Vacío";

$tempo "";
}

Pero lo repito cambiando las variables para cada una de las imagenes siguientes. No quiero escribir la misma chorrada 20 veces si son 20 imagenes a subir, es posible hacer un ciclo o algo así?
No se como =(

Gracias de antemano.
__________________
Cool Village
@Wakkos