I tried to upload the data with ajax file upload and CodeIgniter, I get a problem, the file is successfully uploaded but failed to get value of the data, how to find a solution
<script type="text/javascript">
$(function () {
$("#upload_file").submit(function (event) {
event.preventDefault();
var formData = new FormData($(this)[0]);
$.ajaxFileUpload({
url: '<?php echo base_url(); ?>upload/do_upload',
secureuri: false,
fileElementId: 'upload_doc',
dataType: 'json',
data: formData,
success: function (data, status)
{
if (data.status == 'success')
{
alert(data.msg);
}
}
});
return false;
});
});</script>
and source codeigniter
function do_upload() {
try {
$pesan = "";
$status = "";
$file_element_name = "upload_doc";
$id = $this->input->post('id', true); /* => failed to get data */
if ($id == 0) {
$config['upload_path'] = './files/';
$config['allowed_types'] = 'pdf|docx|doc|txt';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($file_element_name)) {
$status = 'error';
$msg = $this->upload->display_errors('', '');
} else {
$file = $this->upload->data();
$isi['kd_upload'] = $this->mupload->autonumber_upload();
$isi['tgl_upload'] = $this->fungsi_bebas->InggrisTgl($this->input->post('tgl_upload', true)); /* => failed to get data */
$isi['nm_file'] = $file['file_name'];
$isi['no_registrasi'] = $this->input->post('no_registrasi', true); /* => failed to get data */
$isi['validasi'] = "validasi";
$exe = $this->mupload->tambah_upload($isi);
if ($exe > 0) {
$status = "success";
$pesan = "File successfully uploaded" ;
}
}
}
echo json_encode(array('status' => $status, 'msg' => $pesan));
} catch (Exception $exc) {
}
reference : [http://ift.tt/1oeus6x]
Aucun commentaire:
Enregistrer un commentaire