Welcome Guest, Not a member yet? Register   Sign In
Uploading Zip Files
#4

[eluser]mrmeyers99[/eluser]
The rule for this field is in my form_validation:
Code:
$this->form_validation->set_rules('new_reminders', 'New Reminders','callback_isValidFile');

Here is the isValidFile function
Code:
$config['upload_path'] = './reminders/';
$config['allowed_types'] = 'zip';

$this->load->library('upload', $config);

if ( !$this->upload->do_upload('new_reminders'))
{
    $data = $this->upload->data();
    // For testing, print this out
    print_r($data);
    print_r($_POST);
    echo 'input'.$this->input->post('new_reminders');

    // if reminder_package isn't set, new_reminders is required
    if ($this->input->post('reminder_package') == '' && $data['file_name'] == '')
    {
        $this->form_validation->set_message('isValidFile',  'The reminder package field is required.');
        return FALSE;
    }
    // if reminder_package is set, and new_reminders wasn't, that's ok too
    else if ($this->input->post('reminder_package') != '' && $data['file_name'] == '')
    {
        // Normally this would return TRUE, but for testing purposes:
        $this->form_validation->set_message('isValidFile',  'whatever');
        return FALSE;
    }
    
    // Otherwise, show errors          
    $this->form_validation->set_message('isValidFile',  $this->upload->display_errors());
    return FALSE;
}
else
{
    return TRUE;
}

View:
Code:
<?=form_open_multipart('controller/function')?>
        <td>New File:</td>
        <td>&lt;?=form_upload('new_reminders')?&gt;</td>
        <td>&lt;?=form_error('new_reminders')?&gt;</td>
&lt;?=form_close()?&gt;


Messages In This Thread
Uploading Zip Files - by El Forum - 02-28-2009, 12:11 PM
Uploading Zip Files - by El Forum - 02-28-2009, 12:25 PM
Uploading Zip Files - by El Forum - 02-28-2009, 12:47 PM
Uploading Zip Files - by El Forum - 02-28-2009, 12:54 PM
Uploading Zip Files - by El Forum - 02-28-2009, 12:56 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:02 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:10 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:11 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:14 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:16 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:19 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:21 PM
Uploading Zip Files - by El Forum - 02-28-2009, 01:32 PM
Uploading Zip Files - by El Forum - 05-11-2009, 08:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB