I have a form in which I am taking file input that is image, then I send data to my controller with a ajax call but my controller is not getting any file. It is showing me the error {"error":"
You did not select a file to upload.</p>"} My Form
<form action="#" id="formParking" enctype="multipart-form-data">
<div class="input-group">
<div class="col-xs-12 col-sm-4 no_padding">
<label class="">Attachment</label>
</div>
<div class="col-xs-12 col-sm-8">
<div class="col-xs-12 no_space"><input type="file" id="images" name="images" multiple="multiple" /></div>
</div>
</div>
<div class="input-group">
<div class="col-xs-12 col-sm-4 no_padding"> </div>
<div class="col-xs-12 col-sm-8"> <a class="btn blue green text-center" id="btnSave" onclick="saveParking()" >Add</a> </div>
</div>
</form>
Ajax Call
function saveParking()
{
var url;
url = "link_to_controller_function";
$.ajax({
url : url,
type: "POST",
data: $('#formParking').serialize(),
dataType: "JSON",
success: function(data)
{
if(data.status) //if success close modal and reload ajax table
{
location.reload();
}
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error adding / update data');
}
});
}
My Controller
$config['upload_path'] = base_url().'uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 11111;
$config['max_height'] = 76118;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('images'))
{
$error = array('error' => $this->upload->display_errors());
echo json_encode($error);
}
else
{
$data = array('upload_data' => $this->upload->data());
echo json_encode($data);
}