i really need help as this has been giving me problem all day. i only need to upload images from 4 input fields. yet only image from the last input field gets uploaded CODE(function to upload image):
function loadImage($file){
$valid_types = array('jpg','jpeg','png');//allowed img extensions
$ext = strtolower(end(explode('.', $file['name'])));
$size = $file['size'];
if(in_array($ext, $valid_types)){
if($size < (2097152)){
$image_path = substr(md5(time()), 0, 10).'.'.$ext;
if(move_uploaded_file($file['tmp_name'] , "../props/".$image_path)){
return $image_path;
}else{
echo "error";
}
}else{
echo "Image must be less than 2mb";
}
}else{
//echo "image has an invalid file format";
}
}
code to call upload function
$img1 = isset($_FILES['img1']) ? loadImage($_FILES['img1']) : NULL ;
$img2 = isset($_FILES['img2']) ? loadImage($_FILES['img2']) : NULL ;
$img3 = isset($_FILES['img3']) ? loadImage($_FILES['img3']) : NULL ;
$img4 = isset($_FILES['img4']) ? loadImage($_FILES['img4']) : NULL ;
jquery ajax code:
formdata.append('img1', img1);
formdata.append('img2', img2);
formdata.append('img3', img3);
formdata.append('img4', img4);
$.ajax({
url : 'core/upload.php',
type : 'POST',
data : formdata,
contentType : false,
processData : false,
success : function (ep){
alert(ep);
//$('#say').html(ep);
}
});