• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Uploading Zip Files

I'm using the File Upload class to upload a zip file, but something weird is happening. I've tried it with three different zip files. One file works great every time. The other file doesn't upload at all every time. When I do a print_r on the upload data, it says the file name is blank. The third file seems to wipe out all my POST data. Has anyone else had problems like this?

Please post your view and controller method. Thanks.

How big are the files?
What is your upload limit?

The rule for this field is in my form_validation:
$this->form_validation->set_rules('new_reminders', 'New Reminders','callback_isValidFile');

Here is the isValidFile function
$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
    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;
    return TRUE;

        <td>New File:</td>

Doesn't the Upload Class detect file size limit errors?

I guess I should be settings this since my php.ini upload limit is 2M.
$config['max_size'] = '2048';

Still doesn't fix it.

When I upload the one that's too big, the upload data array is empty, like nothing was uploaded at all.

Oh I see, when a file is too big the upload data array doesn't get set.

So I need to check whether someone attempted to upload a file by using this: $_FILES['new_reminders']['name']

Ding-ding-ding-ding-ding! Smile

That should probably be documented a little better. I would think that $this->upload->data() would have all the information (or at least the name) whether it was successful or not.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.