how to unzip uploaded zip file?

Posted by Jaydeepsinh Jadeja on Stack Overflow See other posts from Stack Overflow or by Jaydeepsinh Jadeja
Published on 2012-07-04T08:31:19Z Indexed on 2012/10/20 11:02 UTC
Read the original article Hit count: 158

Filed under:
|
|

I am trying to upload a zipped file using codeigniter framework with following code

function do_upload()
{
    $name=time();
    $config['upload_path'] = './uploadedModules/';
    $config['allowed_types'] = 'zip|rar';
    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_view', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

        $this->load->library('unzip');

    // Optional: Only take out these files, anything else is ignored
    $this->unzip->allow(array('css', 'js', 'png', 'gif', 'jpeg', 'jpg', 'tpl', 'html', 'swf'));

     $this->unzip->extract('./uploadedModules/'.$data['upload_data']['file_name'], './application/modules/'); 



        $pieces = explode(".", $data['upload_data']['file_name']);
        $title=$pieces[0];
        $status=1;
        $core=0;
        $this->addons_model->insertNewModule($title,$status,$core);

    }
}

But the main problem is that when extract function is called, it extract the zip but the result is empty folder. Is there any way to overcome this problem?

© Stack Overflow or respective owner

Related posts about php

Related posts about codeigniter