Advertisement
yhoezt_27

Untitled

Mar 5th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. CONTOH UPLOAD FILE
  2.  
  3. function fileupload($file_array, $post)
  4. {
  5. $response = array();
  6. /*BEGIN FILE UPLOADING CODE */
  7. $uploaded_files = array();
  8.  
  9. if(isset($file_array['input01']) && $file_array['input01']['name']!="")
  10. {
  11. $currentfile_extension = end(@explode(".",$file_array['input01']['name']));
  12. if ($currentfile_extension == 'jpeg' || 'jpg' || 'png')
  13. {
  14. if (isset($post['kd_brng']))
  15. {
  16. $cek = $this->m_all->cek($post['kd_brng'],'kd_brng','tb_barang');
  17. if ($cek->num_rows() > 0)
  18. {
  19. foreach ($cek->result() as $row)
  20. {
  21. $kode = $row->kd_brng;
  22. $nama = $row->nm_brng;
  23. }
  24. $nama_foto = $kode.'_'.$nama.'_'.date("YmdHis").rand(1000,9999).'.'.$currentfile_extension;
  25. $target = "data/ft_brng/".basename($nama_foto);
  26. if(@move_uploaded_file($file_array['input01']['tmp_name'], $target))
  27. {
  28. $info = array(
  29. 'id_foto' => $this->auth->get_jumlah($this->primary, $this->table) + 1,
  30. 'nm_foto' => $nama_foto,
  31. 'alamat' => $target,
  32. 'alamat_url'=> base_url($target),
  33. 'brng_id' => $post['kd_brng'],
  34. 'type_img' => $currentfile_extension,
  35. 'update_date'=>date('Y-m-d H:i:s',now()),
  36. 'update_user'=>$this->session->userdata('username')
  37. );
  38. $this->m_all->simpan($info, $this->table);
  39. $response['status']= "sukses";
  40. $response['pesan'] = "File has been added successfully.";
  41. //$response['url'] = site_url("user_ktr/preview_excell");
  42. } else {
  43. $response['status']= "gagal";
  44. $response['pesan'] = "Error in file uploading.";
  45. }
  46. }
  47. else {
  48. $response['status']= "gagal";
  49. $response['pesan'] = "data null kode barang";
  50. }
  51. }
  52. else {
  53. $response['status']= "gagal";
  54. $response['pesan'] = "null kode barang";
  55. }
  56.  
  57. }
  58. else {
  59. $response['status']= "gagal";
  60. $response['pesan'] = "Format JPEG/JPG/PNG";
  61. }
  62. }
  63. /*END FILE UPLOADING CODE */
  64. echo json_encode($response);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement