Codeigniter File Upload Custom Error Messages
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn codeigniter upload lang more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Codeigniter Custom Validation Error Messages
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like
Codeigniter Custom Form Error Messages
you, helping each other. Join them; it only takes a minute: Sign up How to override validation error messages for file upload class in CI? up vote 0 down vote favorite I have a form which has max
How To Set Custom Error Message In Codeigniter
size limit for attachment when user tries to upload is 10MB ( in my Case). When i try to upload more than that CI redirecting to the form with error message "select a file to upload". But i want error message like this "upload a file which is lesser size than 10MB". How should i over write that error message. Note: I am using CodeIgniter file upload class entirely.......... php codeigniter share|improve this question asked Nov codeigniter ajax file upload 1 '12 at 7:27 Venkat 2,54831440 Do echo ini_get('post_max_size'); and echo ini_get('upload_max_filesize');. Maybe your upload size is limited by php. –air4x Nov 1 '12 at 7:40 i only limited to 10 MB..........but the error message showing when i tried to upload more than that size is unrelated to context....that error message is "You did not select a file to upload" –Venkat Nov 1 '12 at 7:44 I think if the uploaded file size exceeds that set by php (note: not in codeigniter), the file will be ignored by php. So Codeigniter might be finding no file to upload and throwing the error. –air4x Nov 1 '12 at 7:47 If you changed the error message, try submitting the form without uploading any file. –air4x Nov 1 '12 at 7:48 i didn't change error message..............i think it's ignoring file thats y it's giving that error........... –Venkat Nov 1 '12 at 8:02 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted In system/language directory, there is file named upload_lang.php. You can modify error messages from there. share|improve this answer answered Nov 1 '12 at 7:31 kalpesh patel 1,72221236 yeah it's correct but the problem is if i try to upload file with more size why it's giving error "You did
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn codeigniter multiple file upload more about Stack Overflow the company Business Learn more about hiring developers or posting codeigniter file upload error messages ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack you did not select a file to upload. in codeigniter Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up codeigniter file upload up vote 3 down vote favorite I am http://stackoverflow.com/questions/13172744/how-to-override-validation-error-messages-for-file-upload-class-in-ci doing the following to upload a file(image) using codeigniter. What I am wanting to do is modify the error message so that it obvious which field the error relates too as there are multiple upload options on the page, below is my upload code, $config['upload_path'] = './media/uploads/users'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '1000'; $config['max_width'] = '90'; $config['max_height'] = '60'; $this->upload->initialize($config); if(!$this->upload->do_upload('logo_small')) { $error = array('error' => $this->upload->display_errors()); $this->template->build('users/employer', http://stackoverflow.com/questions/6224141/codeigniter-file-upload $error); } else { $file = $this->upload->data(); $logo_small = "small_".$file['file_name']; } So basically I want there error message to state Logo Small in the error message, and then if the error relates to Logo large etc I would want it to state that. php codeigniter file-upload share|improve this question asked Jun 3 '11 at 7:19 Udders 131315 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote easiest way is to edit system/language/english/upload_lang.php with the error message you want. share|improve this answer answered Jun 3 '11 at 12:32 Vamsi Krishna B 5,75364581 3 @Krish: It's a big no-no to edit system/core files. If you can't find a language pack in your specific language you can always make a folder in application/language/ and copy all language files from system/language/english/. In your config, change the default language to whatever you named your folder. Then you can hack away on the files in application/language/yourlang/. First post here on stack overflow so couldn't post this as a comment. It doesn't address the multi file issue. Take a peek at the CI forums; I remember reading something about it on there before. –The Silencer Jun 29 '11 at 14:39 ^^^ agreed! ^
message ($this->upload->display_errors()) 0 Vote(s) - 0 Average 1 2 3 4 5 Thread Modes CI3 Multiple file upload: Custom error message ($this->upload->display_errors()) vrsotto Junior Member Posts: http://forum.codeigniter.com/post-317225.html 18 Threads: 6 Joined: Oct 2014 Reputation: 0 #1 04-22-2015, 12:43 PM https://dannyherran.com/2014/07/validate-forms-file-uploads-with-codeigniter/ (This post was last modified: 04-22-2015, 12:50 PM 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 error message 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 codeigniter file upload 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 Find Reply Avenirer Senior Member Posts: 390 Threads: 15 Joined: Oct 2014 Reputation: 19 #2 04-23-2015, 12:16 AM 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 Or... you can try to extend the upload library. I already tried that. You can see mine here: https://github.com/avenirer/MY_Upload Website: http://avenir.ro Website Find Reply vrsotto Junior Member Posts: 18 Threads: 6 Joined: Oct 2014 Reputation: 0 #3 04-23-2015, 06:17 AM (04-23-2015, 12:16 AM)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 Or... you can try to extend the upload library. I already tried that. You can see mine here: https://github.c
Form Validation class is great to validate simple input fields such as textareas, checkboxes, text fields, etc. But what about file inputs? If you have a mix of text and file inputs, your controller can get messy if you try to validate both. Lets take a look at a neat solution that only involves extending your Form Validation class. First of all we must use CodeIgniter's Form Validation class and extend it. This extension will allow you to save custom errors to the error_array and then print it out as if it was an standard text field. Create a new file named ‘MY_Form_validation.php' and save it to ‘application/libraries'. Add the following code to this file: _error_array[$field])) { $this->_error_array[$field] = $message; } return; } /** * Error Array * * Returns the error messages as an array * * @return array */ function error_array() { if (count($this->_error_array) === 0) return FALSE; else return $this->_error_array; } } /* End of file MY_Form_validation.php */ /* Location: ./application/libraries/MY_Form_validation.php */ Now in order to validate your mixed form you can have your controller do some logic like this: form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('fullname', 'Fullname', 'trim|required'); if ($this->form_validation->run($this)) { // All good, now proceed to file validation if($_FILES['profile_image']['size'] > 0) { $config['upload_path'] = 'assets/profiles/'; $config['allowed_types'] = 'jpg|jpeg|png'; $config['max_size'] = '1024'; $this->upload->initialize($config); if ($this->u