I have a simple html form with a single file upload input. (jsfiddle)
In the past, I have accessed the file selected by the user using input.files
, howe
You have to access the element. Try:
file = $("#fileInput")[0].files[0];
alert(file); //C
or (thank you Jack)
file = $("#fileInput").prop('files')[0];
alert(file);
Fiddle
$(function () {
$("#cmdSubmit").bind("click", function () {
alert(this.files);
});
});
jQuery doesn't provide a wrapper for the Files API. So there isn't a jQuery style way to do this, at least not built into the jQuery core.
Your options:
Try the below code
var file = $("#fileInput").get(0).files[0];
alert(file);
Thanks