How to validate a file upload with the upload class in a multipart form? |
[eluser]bgougent[/eluser]
I have this function Code: function add() where I've put Code: if (!$this->upload->do_upload())
[eluser]skunkbad[/eluser]
Take a look at the upload class, and its methods, and you will see that you don't need to use the form validation class at all (at least for images). If there was some reason to do further validation of an uploaded file, you would extend the upload class. The form validation class validates strings, integers, and boolean values, and is not really suitable for file validation.
[eluser]bgougent[/eluser]
You're correct. But then I need to validate before the form or after the form validation. It would be nice just to have the upload class integrated in the form. It seems that the upload class is more written to use as a stand alone form and not to mix with a default html form. Since I use the upload class my post value of the input-file is empty.
[eluser]skunkbad[/eluser]
I just did this exact same thing for something I'm working on. I have a file upload mixed with 2 standard form input values. If you'd like to see what I did, check out the new inventory controller / add_category method of my Community Cart application, located on Bitbucket: http://bitbucket.org/skunkbad/community-cart While there is probably a more elegant solution, it accomplishes what I needed, and displays the appropriate error messages and confirmation messages.
[eluser]ontguy[/eluser]
This is how I done it. Mainly based on inspiration from others. controller Code: function add() view Code: <?php echo form_open_multipart('admin/product/add'); ?> MY_Form_validation Code: function file_upload_check($file, $required = 'FALSE') in a library Code: function upload_file($field = null) |
Welcome Guest, Not a member yet? Register Sign In |