Reduce Multiple image size in php
<p>Could anyone please help me out, I want to reduce the size of multiple image. but the code reduces just one image from multiple and record just one in mysql. I need help </p>

<pre><code>if(isset($_POST['submitImage'])){
    $file = $_FILES['upload'];
    $errors = array();
    $extensions = array("jpeg","jpg","png"); 


    if(empty($file)){
        $errors[] = ' The file could not be empty ';
    }else{  
     foreach( $file['name'] as $key =&gt; $value ){
     $extensions = array("jpeg","jpg","png"); 
     $file_ext=explode('.',$file['name'][$key]);
     $file_ext=end($file_ext);


    if(in_array($file_ext,$extensions ) === false){
        $errors[]="extension not allowed";
    }else{
        $filetmp = $file['tmp_name'][$key];
        $terget_path = SITE_ROOT.'j2reimage'.DS.'image'.DS;
        $dat = strftime("%Y-%m-%d %H:%M:%S", time());

    if(file_exists($terget_path)){              
</code></pre>

<p>mysql_query("insert into 4j2memberimage values ('', $memmem->id,'{$file['name'][$key]}', $dat')");  </p>

<pre><code>if(move_uploaded_file($filetmp, $terget_path.'/'.$file['name'][$key] )){                    
    $exe = explode(".", $file['name'][$key]);
    $ext = $exe[1];
    $w = 250;
    $h = 250;
        $target  = $terget_path.DS.$file['name'][$key];                 
    $newcopy = SITE_ROOT.'j2reimage'.DS.'reCopy'.DS.$file['name'][$key];
    list($w_orig, $h_orig) = getimagesize($target);
    $scale_ratio = $w_orig / $h_orig;
    if (($w / $h) &gt; $scale_ratio) {
       $w = $h * $scale_ratio;
    } else {
       $h = $w / $scale_ratio;
    }
    $img = "";
    $ext = strtolower($ext);
    if ($ext == "gif"){ 
     $img = imagecreatefromgif($target);
    } else if($ext =="png"){ 
     $img = imagecreatefrompng($target);
    } else { 
     $img = imagecreatefromjpeg($target);
    }
     $tci = imagecreatetruecolor($w, $h);
    imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
    if(@imagejpeg($tci, $newcopy, 80)){
    //  return true;
    $terger_path = $target; 
    //  $terger_path = SITE_ROOT.DS.$this-&gt;img_path.DS.$this-&gt;filename;
     return unlink($terger_path) ? true : false;                        
    }

       }



        //end of if file_exists     
}else{
    $errors[] = ' Upload extention could not be locate';            
}
</code></pre>

<p>}</p>

<p>}
}</p>

<p>}</p>
