$allowed_extensions = array("gif", "jpg", "png", "bmp", "jpe", "jpeg"); [...] for ($image_i = 1; $image_i < ($images_number+1); $image_i++) { $current_image = 'image_'.$image_i; $image = $_FILES[$current_image]['tmp_name']; $image_name = $_FILES[$current_image]['name']; $image_name = str_replace(" ", "_", $image_name); $img_name_arr = explode(".",$image_name); $type = end($img_name_arr); if($image_name == ""){ $img_result .= "<br><font color=red>$current_image -> No File Specified For Upload!</font>"; } elseif( !isset($overwrite) and file_exists($config_path_image_upload."/".$image_name)){ $img_result .= "<br><font color=red>$image_name -> Image already exist!</font>";} elseif( !(in_array($type, $allowed_extensions) or in_array(strtolower($type), $allowed_extensions)) ){ $img_result .= "<br><font color=red>$image_name ->This type of file is not allowed !!!</font>"; } else{ //Image is OK, upload it