Welcome Guest, Not a member yet? Register   Sign In
CI3 Multiple file upload: Custom error message ($this->upload->display_errors())
#3

(04-22-2015, 11:16 PM)Avenirer Wrote: There is not multiple file upload library in CodeIgniter... as I know of... So if you have problems with this you can at any time show us your code Smile Or... you can try to extend the upload library. I already tried that. You can see mine here: https://github.com/avenirer/MY_Upload

basically i followed your tutorial regarding multiple uploading (http://avenir.ro/codeigniter-tutorials/u...deigniter/) with some little modification. I have a MY_Controller class where i wrap the methods.

Here the code doing multiple uploads:

PHP Code:
public function multi_file_upload($field_file_name ''$config = array()) {
 
     $number_of_files count($_FILES[$field_file_name]['tmp_name']);

 
     $files $_FILES[$field_file_name];

 
     if is_array($_FILES[$field_file_name]['tmp_name']) ) {
 
       for ($count 0$count $number_of_files$count++) { 
 
         $this->load->library('upload'$config);

 
         $_FILES[$field_file_name]['name'    $files['name'][$count];
 
         $_FILES[$field_file_name]['type'    $files['type'][$count];
 
         $_FILES[$field_file_name]['tmp_name'] = $files['tmp_name'][$count];
 
         $_FILES[$field_file_name]['error'   $files['error'][$count];
 
         $_FILES[$field_file_name]['size'    $files['size'][$count];

 
         $status[] = $this->single_file_upload($field_file_name$config);
 
       }
 
     }

 
     return $status;
 
   

PHP Code:
public function single_file_upload($field_file_name$config = array()) {
 
 $data = array();

 
 $config['upload_path'] = FCPATH $config['upload_path']; // Must be Writable directory
 
 if ( !is_dir($config['upload_path']) )
 
   mkdir($config['upload_path'], 0777TRUE);

 
 if ($this->upload->do_upload(@$field_file_name)) {
 
   return $this->upload->data();
 
 
 


So to use the functionality
PHP Code:
public function index() {
    
$this->data['views'][] = '_backend/upload';
    
$this->load->view('index'$this->data);
}

public function 
files() {
    
$file_path 'uploads/images/';

    
$config['max_size'] = '1024'// in KB
    
$config['allowed_types'] = 'gif|jpg|png';
    
$config['upload_path'] = $file_path;
    
// $config['overwrite'] = TRUE;

    
$this->multi_file_upload('fld_upload'$config);

    
/**
     * Single upload sample
     */
    // $this->load->library('upload', $config); 
    // $this->single_file_upload('fld_upload', $config);
        
 
       $this->upload->display_errors()
        


As of now i'm looking a way to manage custom file upload error...
Reply


Messages In This Thread
RE: CI3 Multiple file upload: Custom error message ($this->upload->display_error... - by vrsotto - 04-23-2015, 05:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB