CodeIgniter Forums
Yet another .zip file uploading issue - 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: Yet another .zip file uploading issue (/showthread.php?tid=53497)



Yet another .zip file uploading issue - El Forum - 07-26-2012

[eluser]thesleepydog[/eluser]
I searched the forums and tried a few fixes but still can't get my upload function to accept a zip file. Error: Filetype not allowed. Other files listed in the config work fine. Here is my code. Thanks in advance for your time!

Controller
Code:
public function upload_files()
    {
        //check access
        $access = $this->_check_auth_admin();
    
    if ($access != 1)
    {
    show_404();
    }
        
        
        
    $type = $this->input->post('type');
    
    //config for file upload class
    $config['upload_path'] = './partner_assets/' . $type;
    $config['allowed_types'] = 'jpg|png|eps|pdf|doc|xls|ppt|txt|ai|psd|zip';
    $config['max_size'] = '0';
    
    //load additional libraries
    $this->load->helper('form');
    $this->load->library('upload', $config);
    
        //set title
        $this->data['title'] = "Materials Upload";
        
        //get navigation
        $this->data['sections'] = $this->navigator->get_navigator_sections($access);
    
    //set options for form elements
    $this->data['form_options'] = array(
    'id' => 'upload_form'
    );
    
    $this->data['name_options'] = array(
    'id' => 'name',
    'name' => 'name',
    'size' => '46',
    'maxlength' => '50'
    );
    
    $this->data['description_options'] = array(
    'id' => 'description',
    'name' => 'description',
    'rows' => '3',
    'columns' => '25',
    'maxlength' => '100'
    );
    
    $this->data['type_options'] = array(
    'slicks' => 'Slicks',
    'logos'  => 'Logos',
    'manuals' => 'Manuals',
    'documents' => 'Documents'
    );
    
    $this->data['usage_options'] = array(
    'web/screen' => 'Web/Screen',
    'print'  => 'Print',
    );
    
    $this->data['active_options'] = array(
    '1' => 'Yes',
    '0' => 'No',
    );
    
    if ( ! $this->upload->do_upload())
    {
    $this->data['message'] = $this->upload->display_errors();
    
    //generate view
    $this->load->view('templates/header', $this->data);
    $this->load->view('templates/sections', $this->data);
    $this->load->view('materials/upload_files', $this->data);
    $this->load->view('templates/footer');
    }
    else
    {
    //set upload data
    $file = $this->upload->data();
    
    $material_object = new stdClass;
    $material_object->name = $this->input->post('name');
    $material_object->description = $this->input->post('description');
    $material_object->type = $this->input->post('type');
    $material_object->thumbnail = '';
    $material_object->file = url_title($file['file_name'], 'underscore', TRUE);
    $material_object->usage = $this->input->post('usage');
    $material_object->active = $this->input->post('active');
    
    if ( ! $this->materials_model->add_materials_data($material_object))
    {
    
    $this->session->set_flashdata($this->upload->display_errors());
    redirect('materials/upload_files', 'refresh');
    
    }
    else
    {
    //set messages
    $this->session->set_flashdata('message', "You did a great job uploading that file!");
    redirect('materials/index', 'refresh');
    }
    }

    
    }

File
Code:
Array ( [userfile] => Array ( [name] => exx_ptr_logo_pkg.zip [type] => application/zip [tmp_name] => /var/tmp/phpys3tpQ [error] => 0 [size] => 196512 ) )


Mimes.php
Code:
'zip' =>  array('application/zip', 'application/x-zip', 'application/x-zip-compressed', 'application/octet-stream', 'application/x-compress', 'application/x-compressed', 'multipart/x-zip'),




Yet another .zip file uploading issue - El Forum - 07-26-2012

[eluser]john_j[/eluser]
did you add this file type in your configuration file, $config['allowed_types'] ??


Yet another .zip file uploading issue - El Forum - 07-26-2012

[eluser]thesleepydog[/eluser]
Yeah. See line 18ish towards the top of the posted controller code.


Yet another .zip file uploading issue - El Forum - 08-02-2012

[eluser]thesleepydog[/eluser]
Just an update:

I was unable to get the file uploading class to let me specify individual file types separated by a pipe. It would upload a jpg but not any of the other file types. I tried just using a single file type as well. For example $config['allowed_types'] = 'png';. But no luck. It wouldn't let me upload the file. This is strange as I've been able to make this work before.

Solution:

I just allowed all file types with '*' and it works fine. I realize this is not ideal for a public facing page but since the upload page is for administrators who are logged in and that admin is me and a few other people I think it'll be ok.

If anyone can point me in the right direction as to what I'm doing wrong I'd appreciate it. And yes, I have read the manual. Smile

Thanks.