Hola, que tal?
Tengo un codigo que uso para subir imagenes a mi web, las redimensiono, y creo un thumbnail. Pero este codigo funciona solo para subir 1 imagen a la vez.
Me gustaria poder editarlo para que pueda subir n imagenes a la vez, pero no logro hacerlo. Supongo yo que haciendo unos cuantos "for" podria lograrlo, pero no me sale.
Este es mi codigo:
Código PHP:
<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
if (!isset($_SESSION['random_key']) || strlen($_SESSION['random_key'])==0){
$_SESSION['random_key'] = strtotime(date('Y-m-d H:i:s'))."_".$_SESSION['usuario'];
$_SESSION['user_file_ext']= "";
}
$upload_dir = "fotos";
$upload_path = $upload_dir."/";
//prefijo de foto redimensionada
$large_image_prefix = "resize_";
//prefijo de thumbnail
$thumb_image_prefix = "thumbnail_";
//nombre de la foto
$large_image_name = $large_image_prefix.$_SESSION['random_key'];
//nombre del thumbnail
$thumb_image_name = $thumb_image_prefix.$_SESSION['random_key'];
//maximo tamaño de la foto a subir (en mb)
$max_file = "4";
//maximo ancho para redimensionar
$max_width = "900";
//maximo alto para redimensionar
$max_height = "710";
//ancho del thumbnail
$thumb_width = "80";
//alto del thumbnail
$thumb_height = "80";
//extension de imagenes aceptadas
$allowed_image_types = array('image/pjpeg'=>"jpg",'image/jpeg'=>"jpg",'image/jpg'=>"jpg",'image/png'=>"png",'image/x-png'=>"png",'image/gif'=>"gif");
$allowed_image_ext = array_unique($allowed_image_types);
$image_ext = "";
foreach ($allowed_image_ext as $mime_type => $ext) {
$image_ext.= strtoupper($ext)." ";
}
function resizeImage($image,$width,$height,$scale) {
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
$imageType = image_type_to_mime_type($imageType);
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
switch($imageType) {
case "image/gif":
$source=imagecreatefromgif($image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source=imagecreatefromjpeg($image);
break;
case "image/png":
case "image/x-png":
$source=imagecreatefrompng($image);
break;
}
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
switch($imageType) {
case "image/gif":
imagegif($newImage,$image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($newImage,$image,90);
break;
case "image/png":
case "image/x-png":
imagepng($newImage,$image);
break;
}
chmod($image, 0777);
return $image;
}
continua...