CodeIgniter Forums
image form validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: image form validation (/showthread.php?tid=33007)



image form validation - El Forum - 08-12-2010

[eluser]Unknown[/eluser]
Hello,

I created a callback validation for the files uploaded by a form.
here the code:

Code:
function userfile_check(){
        if(isset($_FILES['userfile'])):
            $ff = $_FILES['userfile'];
            if(!$ff['name']):
                $this->form_validation->set_message('userfile_check', 'Image required');
                return FALSE;
            endif;
            $extension= end(explode(".", $ff['name']));
            $ext = array('jpg','png');
            if(!in_array($extension,$ext)):
                $this->form_validation->set_message('userfile_check', 'Image not valid');
                return FALSE;
            endif;
        else:
            $this->form_validation->set_message('userfile_check', 'Image required');
        endif;

    }    



    function add() {

        $this->load->library('form_validation');

        $this->form_validation->set_rules('userfile', 'file', 'callback_userfile_check');

        ...

        }


How can transform userfile_check() for use it in MY_Form_validation.php?
I use an helper for my general functions but also in my helper I can't adapt this code.
Both solutions will be appreciate