im try upload a image from a form with Codeigniter and Ajax. I create the next form structure:
<?php
$config = array('class' => "small-12 columns no-left-margins",'id'=>"form_$i", 'enctype'=>"multipart/form-data");
echo form_open_multipart('', $config);
?>
<!-- file, text, and text area inputs -->
<?php
echo form_close();
?>
<a href="#" class="button tiny right" id="submit" value="upload">Guardar</a>
The Ajax request is:
$("form").submit(function(e){
e.preventDefault();
var datos = $(this).serializeArray();
$.ajax({
url: 'guardarNuevoProducto',
type: 'POST',
data: datos
});
});
And the controller action code is:
// uploadPicture_rules is the index of the $config array that contains the picture //validation rules
$picRules = $this->config->item('uploadPicture_rules');
$this->load->library('upload', $picRules);
if(!$this->upload->do_upload()){
echo json_encode(array('st'=>0, 'msg' => $this->upload->display_errors()));
}else{
echo json_encode(array('st'=>0, 'msg' => 'Successfully Submiited'));
}
And have the next file-upload validation rules:
$config['uploadPicture_rules'] = Array(
'allowed_types' => 'gif|jpg|png',
'max_size' =>'100',
'upload_path' => '/assets'
);
All form values are checked correctly, but the file_uploader says:
{"st":0,"msg":"You did not select a file to upload."}
Any ideas ?. I have a wrong congiruation ?.