Hallo! Selamat Datang di Marketplace produk digital, Freelancer terbaik di indonesia (68409 Members, 793 Products, 5353 Topic, 13045 Comments)

Upload Berkas Tidak Tersimpan Pada Database saat di Simpan (Codeigniter)

Dibuat
Login Terakhir 11 Bulan lalu,
Telah Dilihat 2252 Kali
pramadians Mengatakan : Sultan Account
  1. Assalamualaikum Warahmatullahi Wabarakatuh...
  2.  
  3. Selamat Siang Admin dan rekan-rekan pada forum ini.
  4. Saya mendapatkan masalah ketika mengupload berkas. field berkas tidak tersimpan pada table saat dilakukan proses penyimpanan. Saya menggunakan framework codeigniter dalam membangun aplikasi ini. adapun Controller nya adalah sebagai berikut :
  5.  
  6. public function calendar()
  7. {
  8. $tes = $this->session->userdata['id_organisasi'];
  9. $where = array('id_organisasi' => $tes);
  10. $data = array(
  11. 'user' => $this->aktifrecord->getByParam('user', $where)
  12. );
  13.  
  14. $data_calendar = $this->modeldb->get_list_2();
  15. $calendar = array();
  16.  
  17. $this->load->helper(array('form', 'url'));
  18.  
  19. $config['upload_path'] = './asset/berkas/';
  20. $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf';
  21. $config['encrypt_name'] = TRUE;
  22.  
  23. $this->upload->initialize($config);
  24.  
  25. if ($this->upload->do_upload('berkas'))
  26. {
  27. $gbr = $this->upload->data();
  28.  
  29. $config['image_library']='gd2';
  30. $config['source_image']='./asset/berkas/'.$gbr['file_name'];
  31. $config['create_thumb']= FALSE;
  32. $config['maintain_ratio']= FALSE;
  33. $config['quality']= '50%';
  34. $config['width']= 600;
  35. $config['height']= 400;
  36. $config['new_image']= './asset/berkas/'.$gbr['file_name'];
  37. $this->load->library('image_lib', $config);
  38. $this->image_lib->resize();
  39.  
  40. }
  41.  
  42. foreach ($data_calendar as $key => $val)
  43. {
  44. $color = $val->color;
  45. if ($val->status=="Menunggu disetujui")
  46. {
  47. $color="#C0C0C0";
  48. }
  49.  
  50. $calendar[] = array
  51. (
  52. 'id' => intval($val->id),
  53. 'title' => $val->title,
  54. 'description' => trim($val->description),
  55. 'start' => date_format( date_create($val->start_date) ,"Y-m-d H:i:s"),
  56. 'end' => date_format( date_create($val->end_date) ,"Y-m-d H:i:s"),
  57. 'color' => $color,
  58. 'id_ruang' => $val->id_ruang,
  59. 'time_start' => $val->time_start,
  60. 'time_end' => $val->time_end,
  61. 'status' => $val->status,
  62. 'berkas' => $gbr['file_name'],
  63. );
  64. }
  65.  
  66. $data = array();
  67. $data['get_data'] = json_encode($calendar);
  68.  
  69. $tes = $this->session->userdata['id_organisasi'];
  70. $data['uidt'] = $this->aktifrecord->userIDT($tes);
  71.  
  72. $this->load->view('opd/calendar', $data);
  73.  
  74. }
  75.  
  76. Mohon pencerahan nya Admin dan rekan2 semua. Sebelumnya Saya ucapkan terimakasih. Wassalamu'alaikum warohmatullahi wabarokatuh.
  77.  
Ada 1 File Kiriman :
1. tbl1.jpg (111 KB)

Ada 15 Jawaban

Bukhori Muslim
commented on 10 Mar 2022 06:22:08
  1. Assalamualaikum,.. pastikan pada form filenya sudah ada attribut :
  2. enctype='multipart/form-data'
pramadians
commented on 10 Mar 2022 08:50:44
  1. Assalamualaikum,.. Sudah ada attribut nya pak. seperti ini :
  2.  
  3. <div class="form-group">
  4. <label class="col-lg-2">Input File Dokumen<span class="text-danger"> * </span></label>
  5. <div class="col-lg-6">
  6. <div class="custom-file">
  7. <input type="file" class="form-control" name="berkas" enctype="multipart/form-data" data-toggle="">
  8. </div>
  9. </div>
  10. </div>
PHPMU.COM Support
commented on 10 Mar 2022 09:21:11
  1. Assalamualaikum,.. itu salah mas untuk penempatan attributnya,.. :)
  2. tempatkan pada <form action="" method="" enctype="multipart/form-data">
  3. bukan pada inputannya. hee
pramadians
commented on 10 Mar 2022 09:54:30
  1. Assalamualaikum,..
  2.  
  3. <form class="form-horizontal" method="POST" action="POST" enctype="multipart/form-data">
  4.  
  5. Untuk inputan field selain field berkas, mau tersimpan di database pak, namun untuk field berkas tidak tersimpan pak. Apakah controller nya tidak salah pak??
pramadians
commented on 10 Mar 2022 10:51:12
  1. Assalamualaikum,.. Berikut script controller Sebelum di tambahkan field untuk upload berkas :
  2.  
  3. public function calendar()
  4. {
  5. $tes = $this->session->userdata['id_organisasi'];
  6. $where = array('id_organisasi' => $tes);
  7. $data = array(
  8. 'user' => $this->aktifrecord->getByParam('user', $where)
  9. );
  10.  
  11. $data_calendar = $this->modeldb->get_list_2();
  12. $calendar = array();
  13.  
  14. foreach ($data_calendar as $key => $val)
  15. {
  16. $color = $val->color;
  17. if ($val->status=="Menunggu disetujui")
  18. {
  19. $color="#C0C0C0";
  20. }
  21.  
  22. $calendar[] = array
  23. (
  24. 'id' => intval($val->id),
  25. 'title' => $val->title,
  26. 'description' => trim($val->description),
  27. 'start' => date_format( date_create($val->start_date) ,"Y-m-d H:i:s"),
  28. 'end' => date_format( date_create($val->end_date) ,"Y-m-d H:i:s"),
  29. 'color' => $color,
  30. 'id_ruang' => $val->id_ruang,
  31. 'time_start' => $val->time_start,
  32. 'time_end' => $val->time_end,
  33. 'status' => $val->status,
  34. );
  35. }
  36.  
  37. $data = array();
  38. $data['get_data'] = json_encode($calendar);
  39.  
  40. $tes = $this->session->userdata['id_organisasi'];
  41. $data['uidt'] = $this->aktifrecord->userIDT($tes);
  42.  
  43. $this->load->view('opd/calendar', $data);
  44.  
  45. }
  46.  
  47. Script di atas berhasil melakukan proses penyimpanan data ke database. Namun setelah di tambahkan field 'berkas' pada tabel calender, field berkas tersebut tidak tersimpan pada database dan berkas pun tidak terupload. Terimakasih
PHPMU.COM Support
commented on 10 Mar 2022 17:19:52
  1. Assalamualaikum,.. coba diubah menjadi seperti berikut :
  2. $config['upload_path'] = './asset/berkas/';
  3. $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf';
  4. $config['encrypt_name'] = TRUE;
  5.  
  6. $this->load->library('upload', $config);
  7. $this->upload->do_upload('berkas');
  8. $gbr = $this->upload->data();
  9.  
  10. if ($this->upload->do_upload('berkas'))
  11. {
  12. $config['image_library']='gd2';
  13. $config['source_image']='./asset/berkas/'.$gbr['file_name'];
  14. $config['create_thumb']= FALSE;
  15. $config['maintain_ratio']= FALSE;
  16. $config['quality']= '50%';
  17. $config['width']= 600;
  18. $config['height']= 400;
  19. $config['new_image']= './asset/berkas/'.$gbr['file_name'];
  20. $this->load->library('image_lib', $config);
  21. $this->image_lib->resize();
  22. }
pramadians
commented on 11 Mar 2022 09:30:57
  1. Assalamualaikum,.. Sudah saya ubah scriptnya pak, namun upload berkas belum juga tersimpan. Hanya Field berkas saja yang tidak tersimpan. Adapun script controller terbaru nya adalah sebagai berikut :
  2.  
  3. public function calendar()
  4. {
  5. $tes = $this->session->userdata['id_organisasi'];
  6. $where = array('id_organisasi' => $tes);
  7. $data = array(
  8. 'user' => $this->aktifrecord->getByParam('user', $where)
  9. );
  10.  
  11. $data_calendar = $this->modeldb->get_list_2();
  12. $calendar = array();
  13.  
  14. $config['upload_path'] = './asset/berkas/';
  15. $config['allowed_types'] = 'gif|jpg|png|jpeg|pdf';
  16. $config['encrypt_name'] = TRUE;
  17.  
  18. $this->load->library('upload', $config);
  19. $this->upload->do_upload('berkas');
  20. $gbr = $this->upload->data();
  21.  
  22. if ($this->upload->do_upload('berkas'))
  23. {
  24. $config['image_library']='gd2';
  25. $config['source_image']='./asset/berkas/'.$gbr['file_name'];
  26. $config['create_thumb']= FALSE;
  27. $config['maintain_ratio']= FALSE;
  28. $config['quality']= '50%';
  29. $config['width']= 600;
  30. $config['height']= 400;
  31. $config['new_image']= './asset/berkas/'.$gbr['file_name'];
  32. $this->load->library('image_lib', $config);
  33. $this->image_lib->resize();
  34. }
  35.  
  36. foreach ($data_calendar as $key => $val)
  37. {
  38. $color = $val->color;
  39. if ($val->status=="Menunggu disetujui")
  40. {
  41. $color="#C0C0C0";
  42. }
  43.  
  44. $calendar[] = array
  45. (
  46. 'id' => intval($val->id),
  47. 'title' => $val->title,
  48. 'description' => trim($val->description),
  49. 'start' => date_format( date_create($val->start_date) ,"Y-m-d H:i:s"),
  50. 'end' => date_format( date_create($val->end_date) ,"Y-m-d H:i:s"),
  51. 'color' => $color,
  52. 'id_ruang' => $val->id_ruang,
  53. 'time_start' => $val->time_start,
  54. 'time_end' => $val->time_end,
  55. 'status' => $val->status,
  56. 'berkas' => $gbr,
  57. );
  58. }
  59.  
  60. $data = array();
  61. $data['get_data'] = json_encode($calendar);
  62.  
  63. $tes = $this->session->userdata['id_organisasi'];
  64. $data['uidt'] = $this->aktifrecord->userIDT($tes);
  65.  
  66. $this->load->view('opd/calendar', $data);
  67.  
  68. }
Terdapat 1 File dilampirkan :
1. tbl11.jpg (179 KB)
PHPMU.COM Support
commented on 11 Mar 2022 10:21:22
  1. Assalamualaikum,.. untuk baris penyimpanan nama file ke database jangan diganti lagi,.. :D
  2.  
  3. ini sudah benar : 'berkas' => $gbr['file_name'],
  4. ini salah : 'berkas' => $gbr,
pramadians
commented on 11 Mar 2022 10:28:42
  1. Assalamualaikum,.. 'berkas' => $gbr['file_name'], -------- Tetap Juga tidak mau menyimpan berkas nya pak.
PHPMU.COM Support
commented on 11 Mar 2022 18:36:59
  1. Assalamualaikum,.. coba lebih teliti lagi mas, karena harusnya gak ada masalah lagi.
  2. perhatikan juga extensi file yang di upload gif|jpg|png|jpeg|pdf
  3. dan perhatikan juga upload_path, cek lagi pelan2 keseluruhan. :)
situs slot deposit via dana
commented on 13 Mar 2022 20:44:11
  1. <a href="https://cmensclinic.com/" rel="nofollow"><b>situs slot deposit via dana</b></a>
pramadians
commented on 15 Mar 2022 09:50:23
  1. Assalamualaikum,.. Selamat apagi admin dan teman2...
  2.  
  3. Setelah saya teliti lagi, ternyata file berkas tidak juga tersimpan pada data base. Pada function save, file berkas tidak tersimpan. adapun script form dan function save nya adalah sebagai berikut :
  4.  
  5. <form class="form-horizontal" method="POST" action="POST" id="form_create" enctype="multipart/form-data">
  6. <div class="form-group">
  7. <label class="col-lg-2">Input File Dokumen<span class="text-danger"> * </span></label>
  8. <div class="col-lg-6">
  9. <input type="file" class="form-control" name="berkas">
  10. </div>
  11. </div>
  12. </form>
  13.  
  14. function save()
  15. {
  16. $('#form_create').submit(function(){
  17. var element = $(this);
  18. var eventData;
  19. $.ajax({
  20. url : backend_url+'calendar/save',
  21. type : element.attr('method'),
  22. data : element.serialize(),
  23. dataType: 'JSON',
  24. beforeSend: function()
  25. {
  26. element.find('button[type=submit]').html('<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
  27. },
  28. success: function(data)
  29. {
  30. if(data.status)
  31. {
  32. eventData = {
  33. id : data.id,
  34. title : $('#create_modal input[name=title]').val(),
  35. description : $('#create_modal textarea[name=description]').val(),
  36. start : moment($('#create_modal input[name=start_date]').val()).format('YYYY-MM-DD HH:mm:ss'),
  37. end : moment($('#create_modal input[name=end_date]').val()).format('YYYY-MM-DD HH:mm:ss'),
  38. color : "#C0C0C0",
  39. id_ruang : $('#create_modal input[name=id_ruang]').val(), // Tersimpan
  40. time_start : $('#create_modal input[name=time_start]').val(), // Tersimpan
  41. time_end : $('#create_modal input[name=title_end]').val(), //Tersimpan
  42. status : $('#create_modal input[name=status]').val(), // Tersimpan
  43. berkas : $('#create_modal input[name=berkas]').val(), (Script ini tidak tersimpan kedatabase)
  44. };
  45. $('#calendarIO').fullCalendar('renderEvent', eventData, true);
  46. $('#create_modal').modal('hide');
  47. element[0].reset();
  48. $('.notification').removeClass('alert-danger').addClass('alert-primary').find('p').html(data.notif);
  49. }
  50. else
  51. {
  52. element.find('.alert').css('display', 'block');
  53. element.find('.alert').html(data.notif);
  54. }
  55. element.find('button[type=submit]').html('Submit');
  56. },
  57. error: function (jqXHR, textStatus, errorThrown)
  58. {
  59. element.find('button[type=submit]').html('Submit');
  60. element.find('.alert').css('display', 'block');
  61. element.find('.alert').html('Please save again');
  62. }
  63. });
  64. return false;
  65. })
  66. }
  67.  
  68. Mohon pencerahan nya Admin.....
pramadians
commented on 15 Mar 2022 09:52:21
  1. Assalamualaikum,..
  2.  
  3. Dan ini script Controller function calendar nya:
  4.  
  5. public function calendar()
  6. {
  7. $tes = $this->session->userdata['id_organisasi'];
  8. $where = array('id_organisasi' => $tes);
  9. $data = array(
  10. 'user' => $this->aktifrecord->getByParam('user', $where)
  11. );
  12.  
  13. $data_calendar = $this->modeldb->get_list_2();
  14. $calendar = array();
  15.  
  16. $this->load->helper(array('form', 'url'));
  17.  
  18. $config['upload_path'] = './asset/berkas/';
  19. $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
  20. $config['encrypt_name'] = FALSE;
  21.  
  22. $this->upload->initialize($config);
  23. $this->load->library('upload');
  24. $gbr = $this->upload->data();
  25.  
  26. if ($this->upload->do_upload('berkas'))
  27. {
  28. $config['image_library']='gd2';
  29. $config['source_image']='./asset/berkas/'.$gbr['file_name'];
  30. $config['create_thumb']= FALSE;
  31. $config['maintain_ratio']= FALSE;
  32. $config['quality']= '50%';
  33. $config['width']= 600;
  34. $config['height']= 400;
  35. $config['new_image']= './asset/berkas/'.$gbr['file_name'];
  36. }
  37.  
  38. foreach ($data_calendar as $key => $val)
  39. {
  40. $color = $val->color;
  41. if ($val->status=="Menunggu disetujui")
  42. {
  43. $color="#C0C0C0";
  44. }
  45.  
  46. $calendar[] = array
  47. (
  48. 'id' => intval($val->id),
  49. 'title' => $val->title,
  50. 'description' => trim($val->description),
  51. 'start' => date_format( date_create($val->start_date) ,"Y-m-d H:i:s"),
  52. 'end' => date_format( date_create($val->end_date) ,"Y-m-d H:i:s"),
  53. 'color' => $color,
  54. 'id_ruang' => $val->id_ruang,
  55. 'time_start' => $val->time_start,
  56. 'time_end' => $val->time_end,
  57. 'status' => $val->status,
  58. 'berkas' => $gbr['file_name'],
  59.  
  60. );
  61. }
  62. }
Hardiansyah
commented on 15 Mar 2022 19:09:01
  1. Assalamualaikum,.. untuk upload data lewat ajax ada caranya.
  2. pada form tambah kan id pada input tipe file
  3. <input type="file" class="form-control" id="berkas" name="berkas">
  4.  
  5. coba modifikasi function save nya seperti ini
  6.  
  7. ...
  8. function save()
  9. {
  10. var file_berkas = $('#berkas').prop('files')[0];
  11. var form_data = new FormData();
  12. form_data.append('berkas', file_berkas);
  13. $.ajax({
  14. url: backend_url+'calendar/save',
  15. dataType: 'JSON',
  16. cache: false,
  17. contentType: false,
  18. processData: false,
  19. data: form_data,
  20. type: 'post',
  21. success: function(data)
  22. {
  23. .... lanjutkan sesuai keinginan
  24. }
  25. });
  26. }
  27.  
pramadians
commented on 04 Apr 2022 08:32:23
  1. Assalamualaikum,.. Terimakasih pak atas pencerahan nya,,, Saya coba untuk merubah script ajax nya. Terima kasih.
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!

Online