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

(This post was last modified: 04-22-2015, 11:50 AM by vrsotto.)

Hi All!,

My multiple file uploading is working just fine. But how do i customize/alter file upload error message(s)? let say i have 4 files uploads, 2 files are invalid with each corresponding errors like:

Quote:- The filetype you are attempting to upload is not allowed.
- The file you are attempting to upload is larger than the permitted size.

what would i like is to customize messages some thing like:

Quote:- The filetype (of file2.xxx) you are attempting to upload is not allowed (only jpg|gif|png accepted).
- The file (file3.xxx) you are attempting to upload is larger than the permitted size (of 1000 KB).

with these kind of "error" messaging, it would be easy for user's to identify which file is having issues.

NOTE: I'm not using callback yet

i hope anyone can help...

thanks much in advanced,

vrsotto
Reply
#2

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
Reply
#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
#4

(This post was last modified: 04-23-2015, 05:51 AM by Avenirer. Edit Reason: although... )

GG. Also, I did a pull request on CodeIgniter's github repo: https://github.com/bcit-ci/CodeIgniter/pull/3797. Hope it will get approved. If not, you can at any time change the system files yourself, although I won't encourage you to do that...
Reply
#5
Exclamation 

(04-23-2015, 05:51 AM)Avenirer Wrote: GG. Also, I did a pull request on CodeIgniter's github repo: https://github.com/bcit-ci/CodeIgniter/pull/3797. Hope it will get approved. If not, you can at any time change the system files yourself, although I won't encourage you to do that...

Thanks for pointing me the files from the /system. but, yeah its not wise to touch the core. i hope your pull request granted. if i don't see any other way, i maybe force to slightly modify the core files in the system. Sad

Thanks again!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB