CodeIgniter Forums
Uploading Zip Files - 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: Uploading Zip Files (/showthread.php?tid=16227)

Pages: 1 2


Uploading Zip Files - El Forum - 02-28-2009

[eluser]mrmeyers99[/eluser]
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?


Uploading Zip Files - El Forum - 02-28-2009

[eluser]TheFuzzy0ne[/eluser]
Please post your view and controller method. Thanks.


Uploading Zip Files - El Forum - 02-28-2009

[eluser]pistolPete[/eluser]
How big are the files?
What is your upload limit?


Uploading Zip Files - El Forum - 02-28-2009

[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;



Uploading Zip Files - El Forum - 02-28-2009

[eluser]mrmeyers99[/eluser]
Doesn't the Upload Class detect file size limit errors?


Uploading Zip Files - El Forum - 02-28-2009

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

Still doesn't fix it.


Uploading Zip Files - El Forum - 02-28-2009

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


Uploading Zip Files - El Forum - 02-28-2009

[eluser]mrmeyers99[/eluser]
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']


Uploading Zip Files - El Forum - 02-28-2009

[eluser]TheFuzzy0ne[/eluser]
Ding-ding-ding-ding-ding! Smile


Uploading Zip Files - El Forum - 02-28-2009

[eluser]mrmeyers99[/eluser]
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.