How can I upload multiple images

See all posts Reply

How can I upload multiple images new!
by Sushil, 10 years, 11 months ago
<form name="frm" id="frm" action="" method="post" enctype="multipart/form-data">
<input type="file" name="images[]" multiple="multiple" />
<input type="submit" name="upload" value="upload" />
</form>

By using this code, I am able to select multiple files from my system, But i not getting how can use this to upload multiple images with this class.

Please give me solution!!1
ThanksReply
Re: How can I upload multiple images new!
by colin, 10 years, 11 months ago
Please read the FAQReply
Re: How can I upload multiple images new!
by Sushil, 10 years, 11 months ago
Thanks for nice support!!Reply
Re: How can I upload multiple images new!
by Ricardo, 10 years, 3 months ago
Hi,

I tried a multiple upload and making at the same time a thumb for each picture. But it didn't work.

Here is de code:

session_start();
error_reporting(0);
ini_set("max_execution_time",0);

//if($_POST['nuevo'] && $_POST['Categoria'])
if(isset($_FILES['files'])){
  include("conexion.php");
  include("funciones.php");
  include("lib/class.upload.php");

  //UPLOADS PHOTOS
  // we instanciate the class for each element of $file
  $files = array();
  foreach ($_FILES['Foto'] as $k => $l) {
   foreach ($l as $i => $v) {
   if (!array_key_exists($i, $files))
     $files[$i] = array();
     $files[$i][$k] = $v;
   }
  }      

  foreach ($files as $file) {
    $handle = new Upload($file);
    if ($handle->uploaded) {
      $handle->Process("../uploads/galeria/mas/");
      if ($handle->processed) {
        echo 'OK';
      } else {
        echo 'Error: ' . $handle->error;
      }
    } else {
      echo 'Error: ' . $handle->error;
    }
    unset($handle);
  }      
  
  //$handle = new Upload($_FILES['Foto'], 'es_ES');
  
  // then we check if the file has been uploaded properly
  // in its *temporary* location in the server (often, it is /tmp)
  if ($handle->uploaded) {

    //NORMAL
    $nombre_imagen = date('YmdHis') .'_'.RandomString(5,FALSE,FALSE,FALSE);
    
    //$handle->file_max_size = '1024'; // 1KB
    //$handle->allowed = array('application/pdf','application/msword', 'image/*');
    
    $handle->file_new_name_body    = $nombre_imagen;
    $handle->file_name_body_add    = '';
    
    if($handle->image_src_x > 600) {
      $handle->image_resize          = true;
      $handle->image_ratio_y         = true;
      //$handle->image_ratio           = true;
      //$handle->image_y               = 280;
      $handle->image_x               = 600;
      
    }
    
    $handle->image_convert         = 'jpg';
    $handle->jpeg_quality          = 90;
    
    $handle->Process("../uploads/galeria/mas/");
    
    //MINIATURA
    $handle->file_new_name_body    = 'min_'.$nombre_imagen;
    $handle->image_resize          = true;
    //$handle->image_ratio           = true;
    $handle->image_ratio_crop     = true;
    $handle->image_y               = 140;
    $handle->image_x               = 140;
    $handle->image_convert         = 'jpg';
    $handle->jpeg_quality          = 90;
        
    $handle->Process("../uploads/galeria/mas/");
          
    // we check if everything went OK
    if ($handle->processed) {
      // everything was fine !
      $Foto = $nombre_imagen.".jpg";

    } else {
      // one error occured
      //No se Subio
    }
    
    
  } else {
    // if we're here, the upload file failed for some reasons
    //otros errores
  }
  //FIN FOTO

  $sql = "INSERT INTO img (Nombre,Categoria,Subcategoria,Foto) 
  VALUES ('".$_POST['Nombre']."','".$_POST['Categoria']."', '".$_POST['Subcategoria']."', '".$Foto."')";
  $res = mysql_query($sql);

  if($res)
  {
    header("Location:index.php?seccion=trabajos-fotos&nuevo=ok");
    exit();
  }else{
    header("Location:index.php?seccion=trabajos-fotos&error=1");
    exit();
  }
  
} else {
  if (!$_SESSION['user_id'] || !$_SESSION['user_name'] || !$_SESSION['logged']== "admin")
  {
    echo "Deny";
    exit();
  }
}

$c = mysql_fetch_array( mysql_query("SELECT * FROM img WHERE MD5(id) = '".$_GET['id']."' ") );

Can you help me, please?Reply
Re: How can I upload multiple images new!
by colin, 10 years, 3 months ago
You should check the log produced by the class.

But also, it seems that you should remove the line unset($handle);, because if you leave it you destroy the class instance.Reply
Re: How can I upload multiple images new!
by Ricardo, 10 years, 3 months ago
Nope, it's still giving the same problem. The script injects the data correctly, but it doesn't upload the piicture and neither the name of the photo.Reply
Re: How can I upload multiple images new!
by colin, 10 years, 3 months ago
Please copy here the logs produced by the class.Reply