Advertisement
fida_muntaseer

UploadMultiTag

Mar 19th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2.  
  3. class UploadMultiTag extends CI_Controller
  4. {
  5.     public $success = array(
  6.         'status' => 'success',
  7.     );
  8.  
  9.     public $fail = array(
  10.         'status' => 'fail',
  11.     );
  12.  
  13.     public $result = false;
  14.  
  15.     public function __construct()
  16.     {
  17.         parent::__construct();
  18.  
  19.     }
  20.  
  21.     public function index()
  22.     {
  23.        
  24.         $username = $this->input->post('username');
  25.         $email = $this->input->post('email');
  26.         $password = $this->input->post('password');
  27.        
  28.        
  29.        if (!empty($username) && !empty($password) && !empty($email) && !empty($_FILES["userfile1"]) && !empty($_FILES["userfile2"]) && !empty($_FILES["userfile2"])) {
  30.         $this->success['username'] = $username;
  31.         $this->success['password'] = $password;
  32.         $this->success['email'] = $email;
  33.             $this->do_upload();
  34.         } else {
  35.             $this->result = false;
  36.             print_r(json_encode($this->fail));
  37.         }
  38.     }
  39.  
  40.     public function do_upload()
  41.     {
  42.         $config['upload_path'] = './uploads/';
  43.         $config['allowed_types'] = 'gif|jpg|png';
  44.         $config['max_size'] = 10000;
  45.         $config['max_width'] = 10240;
  46.         $config['max_height'] = 7680;
  47.         $config['encrypt_name'] = true;
  48.  
  49.         $this->load->library('upload', $config);
  50.  
  51.         if ($this->upload->do_upload('userfile1')) {
  52.             $upload_data = $this->upload->data();
  53.             $file_name = $upload_data['file_name'];
  54.             $this->success['userfile1'] = $file_name;
  55.             $this->result = true;
  56.         } else {
  57.             $this->result = false;
  58.         }
  59.  
  60.         if ($this->upload->do_upload('userfile2')) {
  61.             $upload_data = $this->upload->data();
  62.             $file_name = $upload_data['file_name'];
  63.             $this->success['userfile2'] = $file_name;
  64.             $this->result = true;
  65.         } else {
  66.             $this->result = false;
  67.         }
  68.  
  69.         if ($this->upload->do_upload('userfile3')) {
  70.             $upload_data = $this->upload->data();
  71.             $file_name = $upload_data['file_name'];
  72.             $this->success['userfile3'] = $file_name;
  73.             $this->result = true;
  74.         } else {
  75.             $this->result = false;
  76.         }
  77.  
  78.         if ($this->result === true) {
  79.             print_r(json_encode($this->success));
  80.         } else {
  81.             print_r(json_encode($this->fail));
  82.         }
  83.     }
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement