Virajsinh

Codeigniter Different File Upload

Jan 3rd, 2020
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $image_data = array();
  2. $document_data = array();
  3.  
  4. // load library only once
  5. $this->load->library('upload');
  6.  
  7. // image configuration
  8. $image_config['upload_path'] = './uploads/';
  9. $image_config['allowed_types'] = 'gif|jpg|png';
  10. $image_config['max_size']    = '1000';
  11. $image_config['max_width']  = '1024';
  12. $image_config['max_height']  = '768';
  13.  
  14. $this->upload->initialize($image_config);
  15.  
  16. // process image upload first
  17. if ( ! $this->upload->do_upload('image'))
  18. {
  19.    // image upload error , display error etc.
  20. }
  21. // image was uploaded properly, continue
  22. else
  23. {
  24.    $image_data = $this->upload->data();
  25.  
  26.    // document configuration
  27.    $document_config['upload_path'] = './uploads/';
  28.    $document_config['allowed_types'] = 'pdf';
  29.  
  30.    $this->upload->initialize($document_config);
  31.  
  32.    if ( ! $this->upload->do_upload('document'))
  33.    {
  34.       // document upload error , display error etc.
  35.       // you might need to delete the former uploaded image file ...
  36.    }
  37.    else
  38.    {
  39.       $document_data = $this->upload->data();
  40.    }
  41. }
RAW Paste Data