Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Cara membuat fungsi upload di ci
function save()
{
$getkodeticket = $this->model_app->getkodeticket();
$ticket = $getkodeticket;
$id_user = strtoupper(trim($this->input->post('id_user')));
$tanggal = $time = date("Y-m-d H:i:s");
$id_sub_kategori = strtoupper(trim($this->input->post('id_sub_kategori')));
$id_kategori = strtoupper(trim($this->input->post('id_kategori')));
$id_kondisi = strtoupper(trim($this->input->post('id_kondisi')));
$problem_summary = strtoupper(trim($this->input->post('problem_summary')));
$problem_detail = strtoupper(trim($this->input->post('problem_detail')));
$id_teknisi = strtoupper(trim($this->input->post('id_teknisi')));
$data['id_ticket'] = $ticket;
$data['reported'] = $id_user;
$data['tanggal'] = $tanggal;
$data['id_sub_kategori'] = $id_sub_kategori;
$data['problem_summary'] = $problem_summary;
$data['problem_detail'] = $problem_detail;
$data['id_teknisi'] = $id_teknisi;
$data['status'] = 1;
$data['progress'] = 0;
//proses upload file
// $config['upload_path'] = './assets/files/'; //path folder
// $config['allowed_types'] = 'pptx|pdf|doc|docx|ppt|rar|zip'; //type yang dapat diakses bisa anda sesuaikan
// $config['remove_spaces'] = TRUE;
// $config['overwrite'] = FALSE;
// $config['min_size'] = 0;
// $config['max_size'] = 10000;
// $this->upload->initialize($config);
$filesize = 0;
if(is_array($_FILES)){
if($_FILES['file_attachment']['name']!=""){
$filesize = $_FILES['file_attachment']['size'];
$data['filename_attachment'] = $_FILES['file_attachment']['name'];
$data['file_attachment'] = file_get_contents($_FILES['file_attachment']['tmp_name']);
$fileDestination = './assets/files'.$data;
move_uploaded_file($data, $fileDestination);
}
}
// end upload
$tracking['id_ticket'] = $ticket;
$tracking['tanggal'] = $tanggal;
$tracking['status'] = "Created Ticket";
$tracking['deskripsi'] = "";
$tracking['id_user'] = $id_user;
if($filesize > 10000000){
$this->session->set_flashdata("msg", "<div class='alert bg-success' role='alert'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<svg class='glyph stroked empty-message'><use xlink:href='#stroked-empty-message'></use></svg> Ukuran file terlalu besar (max 10Mb).
</div>");
redirect('myticket/myticket_list');
}else{
$this->db->trans_start();
$this->db->insert('ticket', $data);
$this->db->insert('tracking', $tracking);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE){
$this->session->set_flashdata("msg", "<div class='alert bg-danger' role='alert'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<svg class='glyph stroked empty-message'><use xlink:href='#stroked-empty-message'></use></svg> Data gagal tersimpan.
</div>");
redirect('myticket/myticket_list');
}else{
// email ke admin
$akses = $this->db->query("select username FROM user WHERE level = 'ADMIN'")->result();
$username_tiket = $this->db->query("SELECT nama FROM karyawan WHERE nik = '$id_user' ")->row();
$nama_user_tiket = $username_tiket->nama;
$row_kategori = $this->db->query("SELECT nama_kategori FROM kategori WHERE id_kategori = '$id_kategori' ")->row();
$nama_kategori = $row_kategori->nama_kategori;
$row_sub_kategori = $this->db->query("SELECT nama_sub_kategori FROM sub_kategori WHERE id_sub_kategori = '$id_sub_kategori' ")->row();
$nama_sub_kategori = $row_sub_kategori->nama_sub_kategori;
$row_kondisi = $this->db->query("SELECT nama_kondisi FROM kondisi WHERE id_kondisi = '$id_kondisi' ")->row();
$nama_kondisi = $row_kondisi->nama_kondisi;
if($akses!=null){
foreach($akses as $data){
$row_user = $this->db->query("SELECT email FROM user WHERE username = ".$data->username)->row();
$to = $row_user->email;
$data_tiket = array(
'no_tiket' => $tracking['id_ticket'],
'user_tiket' => $tracking['id_user'],
'username_tiket' => $nama_user_tiket,
'sub_kategori_tiket' => $nama_sub_kategori,
'kategori_tiket' => $nama_kategori,
'kondisi_tiket' => $nama_kondisi,
'subject_masalah' => $problem_summary,
'deskripsi_masalah' => $problem_detail,
);
$body_email = $this->load->view('email/template.php',$data_tiket,TRUE);
$message = $body_email;
$subject = $tracking['id_ticket'];
$this->load->helper('Email');
send($to,$message,$subject);
}
}
$this->session->set_flashdata("msg", "<div class='alert bg-success' role='alert'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<svg class='glyph stroked empty-message'><use xlink:href='#stroked-empty-message'></use></svg> Data tersimpan.
</div>");
redirect('myticket/myticket_list');
}
}
}
}
tolong aku suhu aku bingung cara bikin upload file, masih newbie :(
Tanggapan
bingungnya dmn ?
errornya apa, masalah kode kamu yang kamu tampilkan kenapa, coba diperjelas,
jadi koding di atas itu untuk upload gan, cuman pas saya masukan file terus di klik simpan, file tidak tersimpan di folder tujuan :(
$filesize = 0; if(is_array($_FILES)){ if($_FILES['file_attachment']['name']!=""){ $filesize = $_FILES['file_attachment']['size']; $data['filename_attachment'] = $_FILES['file_attachment']['name']; $data['file_attachment'] = file_get_contents($_FILES['file_attachment']['tmp_name']); $fileDestination = './assets/files'.$data; move_uploaded_file($data, $fileDestination);
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban