Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/01/2016, 09:01
cvelazco2011
 
Fecha de Ingreso: diciembre-2015
Mensajes: 5
Antigüedad: 9 años
Puntos: 0
Problema guardar imagen modal bootstrap

hola expertos tengo un pequeño problema estoy un mant CRUD con ajax js bootstrap en codeigniter
Ingreso todos los datos a traves de un modal bootstrap todos los datos los guarda de manera correcta pero por alguna razon parece que no capturar la data de la imagen y guarda la imagen por default que le digo en el codigo si en caso la variable uimagen esta vacia que me guarde default.png

por favor endonde me estoy equivocando


esta es la vista de mi controlador y mi vista

--------------------controller person

public function ajax_add()

{

$this->_validate();

$config['upload_path'] = './imagenes/';

$config['allowed_types'] = 'gif|jpg|png';

$config['max_size'] = 1000;

$config['max_width'] = 1024;

$config['max_height'] = 768;

$config['encrypt_name'] =TRUE;

$this->load->library('upload', $config);

$this->upload->do_upload('imagenes');

$data = $this->upload->data();

$imagenes=$data['file_name'];

if (empty($imagenes)) {

$imagenes="default.jpg";

}



$data = array(

'firstName' => $this->input->post('firstName'),

'lastName' => $this->input->post('lastName'),

'gender' => $this->input->post('gender'),

'address' => $this->input->post('address'),

'dob' => $this->input->post('dob'),

'codist' => $this->input->post('codist'),

'codcargo' => $this->input->post('codcargo'),

'imagen' => $imagenes,



);

$insert = $this->person->save($data);

echo json_encode(array("status" => TRUE));

}


---------------------------person_view.php



<script type="text/javascript">
function save()
{
$('#btnSave').text('saving...'); //change button text
$('#btnSave').attr('disabled',true); //set button disable
var url;

if(save_method == 'add') {
url = "<?php echo site_url('person/ajax_add')?>";
} else {
url = "<?php echo site_url('person/ajax_update')?>";
}
// ajax adding data to database
$.ajax({
url : url,
type: "POST",
data: $('#form').serialize(),
dataType: "JSON",
success: function(data)
{

if(data.status) //if success close modal and reload ajax table
{
$('#modal_form').modal('hide');
reload_table();
}
else
{
for (var i = 0; i < data.inputerror.length; i++)
{
$('[name="'+data.inputerror[i]+'"]').parent().parent().addClass('has-error'); //select parent twice to select div form-group class and add has-error class
$('[name="'+data.inputerror[i]+'"]').next().text(data.error_string[i]); //select span help-block class set text error string
}
}
$('#btnSave').text('save'); //change button text
$('#btnSave').attr('disabled',false); //set button enable
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error adding / update data');
$('#btnSave').text('save'); //change button text
$('#btnSave').attr('disabled',false); //set button enable

}
});
}
</script>

<div class="modal fade" id="modal_form" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h3 class="modal-title">Person Form</h3>
</div>
<div class="modal-body form" role="form">
<form action="#" method="POST" id="form" class="form-horizontal" enctype="multipart/form-data">

<div class="fileupload fileupload-new" data-provides="fileupload">

<div class="fileupload-preview thumbnail" data-trigger="fileupload" style="width: 100px; height: 100px;"></div>

<div>

<span class="btn btn-default btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span>

<input type="file" id="imagenes" name="imagenes">

<input type="hidden" class="form-control" id="OLD_IMG" name="OLD_IMG" >

</span>



<a href="#" id="re_image" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>

</div>

</div>

</form>
</div>
</div>
</div>
</div>