nebukad

Codeigniter Upload Multiple

Apr 28th, 2015
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <!-- form upload -->
  2. <?php echo $error;?>
  3. <?php echo form_open_multipart('upload/upload');?>
  4. Dokumen : <input type="file" name="dokumen" size="20" /><br>
  5. Foto : <input type="file" name="foto" size="20" />
  6. <br /><br />
  7. <input type="submit" value="upload" />
  8.  
  9.  
  10.  
  11. /**
  12. * Handle form upload
  13. */
  14. function upload()
  15. {
  16.     $dokumen = $this->do_upload('dokumen');
  17.     $file = $this->do_upload('file');
  18.     $error = [];
  19.     $data = array('upload_dokumen'=>$dokumen['upload_data'], 'upload_file'=>$file['upload_data']);
  20.     if(isset($dokumen[error])){
  21.         $error['error_dokumen'] = $dokumen['error'];
  22.     }  
  23.     if(isset($file[error])){
  24.         $error['error_file'] = $file['error'];
  25.     }
  26.  
  27.     if(isset($error))
  28.         // jika error
  29.         $this->load->view('upload_form', $error);
  30.     }else{
  31.         // jika gak error
  32.         $this->load->view('upload_sukses', $data);
  33.     }  
  34. }
  35. function do_upload($file_name)
  36. {
  37.  
  38.     $this->load->library('upload');
  39.  
  40.     $config['upload_path'] = './uploads/';
  41.     $config['allowed_types'] = 'doc|docx|pdf|csv';
  42.     $config['max_size'] = '5120000'; // 5MB
  43.     $this->upload->initialize($config); // Important
  44.     $this->upload->do_upload($file_name);
  45.        
  46.  
  47.     if (!$this->upload->do_upload())
  48.     {
  49.         $error = array('error' => $this->upload->display_errors());
  50.         return $error;
  51.     }
  52.     else
  53.     {
  54.         $data = array('upload_data' => $this->upload->data());
  55.         return $data;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment