<td>
<input type="file" id="fileIMG3" name="fileIMG3"
accept="application/pdf" >
</td
- sender.php
if(!empty($_FILES['fileIMG3']['type'])){
$target_path3 = $_FILES['fileIMG3']['name'];
$valid_extensions3 = array('pdf');
$temporary3 = explode(".", $_FILES["fileIMG3"]["name"]);
$file_extension3 = end($temporary3);
if((($_FILES["fileIMG3"]["type"] == "img/pdf"))
&& in_array($file_extension3, $valid_extensions3)){
$target_path3 = "img/";
$target_path3 = $target_path3.basename
($_FILES['fileIMG3']['name']);
move_uploaded_file($_FILES['fileIMG3']['name']
,$target_path3 );
$uploadedFile3 = $target_path3;
}
}
- sendData.js
$(document).ready(function(){
$("#sendForm").on('submit', function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'sender.php',
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
beforeSend: function(){
$('.submitBtn').attr("disabled","disabled");
$("#sendForm")[0].reset();
},
success: function(msg){
$('#fupForm').css("opacity","");
$(".submitBtn").removeAttr("disabled");
}
});
});
//file type validation
$("#send_data").change(function() {
var file = this.files[0];
var imagefile = file.type;
var match=
["image/jpeg","image/png","image/jpg", "img/pdf"];
if(!((imagefile==match[0]) || (imagefile==match[1])
|| (imagefile==match[2]) || (imagefile==match[3]))){
alert('Please select a valid image file
(JPEG/JPG/PNG/PDF).');
$("#send_data").val('');
return false;
}
});
});