<?php
$timex = time();
$fileA = "file1";
$fileA_Title = 'Profile Picture';
$uploaded_images = array();
$total_images = count($_FILES[$fileA]['name']);
$files = $_FILES[$fileA]['name'][0];
$filenames = "";
if(!empty($files)){
if($total_images<=1){
foreach($_FILES[$fileA]['name'] as $key=>$val){
$upload_dir = "../j_files/j_img/users/passport/";  	  	
$upload_file = $upload_dir.$_FILES[$fileA]['name'][$key];
$filename = $_FILES[$fileA]['name'][$key];
//
$ext = explode('.', basename($_FILES[$fileA]['name'][$key]));//explode file name from dot(.) 
$file_extension = strtolower(end($ext)); //store extensions in the variable
//
$validextensions = array("jpeg", "jpg", "png","gif");  //Extensions which are allowed
if (in_array($file_extension, $validextensions)) {				
$extx = ".$file_extension";
//
$nom = $key+1; //file numbering for user to understand.
//$new_filename = "$transact_id$key$timex$extx"; //rename file
$new_filename = "$timex$id$key$extx"; //rename file
$upload_file = "$upload_dir$new_filename"; //rename file
if(move_uploaded_file($_FILES[$fileA]['tmp_name'][$key], ''.$upload_file)){ //SAVE FILE
//$filenames .="".$new_filename.",";  
$filenames .="".$new_filename."";  
//}
}else{ die("<div class='alert alert-danger'>Unable to upload $fileA_Title. Please choose another.</div>"); }
}else{ die("<div class='alert alert-danger'>$fileA_Title type is invalid, Please choose another.</div>"); }
} //end loop
}else{ die("<div class='alert alert-danger'>Please, you can only upload 1 $fileA_Title file at a time.</div>"); }
}else{ die("<div class='alert alert-danger'>Please add $fileA_Title</div>"); }
//$filenames = mb_substr($filenames,0,-1);
//echo $filenames;
?>