Welcome Guest, Not a member yet? Register   Sign In
File uploading: Do not require a file to be uploaded
#2

[eluser]garymardell[/eluser]
I assume you have something like this a callback to do the upload.

Code:
function _upload_file()
    {
    
        // try to upload the form return error if failed.
        
        $config['upload_path'] = './public/uploads/sermons/';
        $config['allowed_types'] = 'mp3|jpg|jpeg';
        $config['max_size']    = '2000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
                
        
        if (!$this->upload->do_upload("sermon"))
        {
            $this->form_validation->set_message('_upload_file', 'The file could not be uploaded.');
            return false;
        }
        else
        {
            return true;
        }
    }

Now in the callback you could add a check to see if the other field was filled in.

Code:
function _upload_file()
    {
        if(!empty($this->input->post("field_name")))
        {
            return true;
        }
    
        // try to upload the form return error if failed.
        
        $config['upload_path'] = './public/uploads/sermons/';
        $config['allowed_types'] = 'mp3|jpg|jpeg';
        $config['max_size']    = '2000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
                
        
        if (!$this->upload->do_upload("sermon"))
        {
            $this->form_validation->set_message('_upload_file', 'The file could not be uploaded.');
            return false;
        }
        else
        {
            return true;
        }
    }

This will check if the other field is filled in and if it is then it will return true, so the upload will not be done and for the validation purposes will appear successful (basically skipped).


Messages In This Thread
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 12:33 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 12:51 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 01:07 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 02:37 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 05:01 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 10:20 AM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 10:26 AM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 11:20 AM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 12:09 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 12:57 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 01:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB