Advertisement
juliarnasution

controller upload multiple file

Mar 21st, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @Author: juliarnasution
  5.  * @Date:   2020-03-21 17:03:07
  6.  * @Last Modified by:   Dell
  7.  * @Last Modified time: 2020-03-21 17:13:49
  8.  */
  9.  
  10.  
  11. class Dokumen extends CI_Controller
  12. {
  13.     public function uploadfile()
  14.     {
  15.         if(array_key_exists('file1',$_FILES) && $_FILES['file1']['size']>0){
  16.             $file1 = $this->upload_file1('file1');//upload $)FILES['file1'];
  17.             if ($file1['result']==false) {
  18.                 echo "error : gagal di upload";
  19.             }else{
  20.                 echo "file1 berhasil di upload";
  21.             }
  22.         }
  23.  
  24.         if(array_key_exists('file2',$_FILES) && $_FILES['file2']['size']>0){
  25.             $file2 = $this->upload_file2('file2');//upload $)FILES['file2'];
  26.             if ($file2['result']==false) {
  27.                 echo "error : gagal di upload";                
  28.             }else{
  29.                 echo "file2 berhasil di upload";
  30.             }
  31.         }
  32.     }
  33.  
  34.     public function upload_file1($data)
  35.     {  
  36.         $config['upload_path'] = './files' ;
  37.         $config['allowed_types'] = 'jpg|jpeg|png';
  38.         $config['max_size']  = '400';
  39.         $config['remove_space'] = TRUE;
  40.         $config['file_name'] = $data;
  41.        
  42.         $this->load->library('upload', $config,'file1');//membuat object dengan nama file1
  43.         $this->file1->initialize($config);
  44.         if (!$this->file1->do_upload($data)){
  45.             return array('result'=>FALSE,'file'=>'','error' => $this->file1->display_errors());
  46.         }
  47.         else{
  48.             return array('result'=>TRUE,'file'=>$this->file1->data(),'upload_data' => $this->file1->data());          
  49.         }
  50.     }
  51.  
  52.     public function upload_file2($data)
  53.     {  
  54.         $config['upload_path'] = './files' ;
  55.         $config['allowed_types'] = 'jpg|jpeg|png';
  56.         $config['max_size']  = '400';
  57.         $config['remove_space'] = TRUE;
  58.         $config['file_name'] = $data;
  59.        
  60.         $this->load->library('upload', $config,'file2');//membuat object dengan nama file2
  61.         $this->file2->initialize($config);
  62.         if (!$this->file2->do_upload($data)){
  63.             return array('result'=>FALSE,'file'=>'','error' => $this->file2->display_errors());
  64.         }
  65.         else{
  66.             return array('result'=>TRUE,'file'=>$this->file2->data(),'upload_data' => $this->file2->data());          
  67.         }
  68.     }
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement