I have following HTML object with file
<form name='file_form' class="panel-body">
<input type="file" id="file" name="file[]" />
<input type='button' id='btnSendFile' value='sendFile' />
<output id="list"></output>
</form>
Where using the file browse in type="file", I select a file to upload. When I click on btnSendFile, the file name of the selected file appears under name. However file variable is null when I pass it below. I need to access file object properties of file object.
I have a function that sends the file.
var file ;
function sendFile(file) {
var to = $('#to').get(0).value;
var filename = file.name;
var filesize = file.size;
var mime = file.type;
}
$('#btnSendFile').bind('click', function() {
sendFile(file);
});
How do I get the file object in javascript where I need to file.name, file.size, and file.type? What should I assign variable file ?
UPDATE: Answer:
file= $("#file")[0].files[0];
sendFile?sendFile();