Use below javascript function:
function uploadFile(fileObj) {
var formData = new FormData();
formData.append("file", fileObj.files[0]);
var url = "sv/upload-file.php?action=upload-image";
$.ajax({
type : "POST",
url : url,
cache : false,
contentType : false,
processData : false,
data : formData,
success : function(json) {
console.log(json);
},
error : function (err){
console.log(json);
}
});
}
And in Html code:
<input type="file" onchange="uploadFile(this)" />
Write your server side code in php, java or any other language.
If any doubt ask in comments.
Node.js for the server side! :D
ReplyDeleteyes, right
ReplyDelete