I have created a admin template page in magento. ON this page I created a form to browse a csv file and on click submit button I want to send this via ajax to a controller action and there I want to get csv data and insert into custom table.
Below is my code :
<input type="file" name="file" id="file" />
<button name="submit" id="import_button" value="" type="submit" onclick="importData()" >Submit</button>
and ajax is here :
function importData()
{
var file = jQuery('input[type=file]').prop("files")[0];
ajaxBlockUrl = '<?php echo $this->getUrl('*\/*\/import') ?>';
new Ajax.Request(ajaxBlockUrl, {
method: 'POST',
parameters: {isAjax: 'true', form_key: FORM_KEY, file : file},
onSuccess: function (response)
{
// success
}
});
}
and my controller action :
// how to I get file here
$_FILES['file']['name'];
$file = $this->getRequest()->getParam('file');
My ajax calls successfully controller action but How do I get file here and read data from it?