uploading zip files in codeigniter won't work

Posted by krike on Stack Overflow See other posts from Stack Overflow or by krike
Published on 2010-04-27T05:48:11Z Indexed on 2010/04/27 5:53 UTC
Read the original article Hit count: 336

Filed under:
|

I have created a helper that requires some parameters and should upload a file, the function works for images however not for zip files. I searched on google and even added a MY_upload.php -> http://codeigniter.com/bug_tracker/bug/6780/

however I still have the problem so I used print_r to display the array of the uploaded files, the image is fine however the zip array is empty:

Array
(
    [file_name] => 
    [file_type] => 
    [file_path] => 
    [full_path] => 
    [raw_name] => 
    [orig_name] => 
    [file_ext] => 
    [file_size] => 
    [is_image] => 
    [image_width] => 
    [image_height] => 
    [image_type] => 
    [image_size_str] => 
)

Array
(
    [file_name] => 2385b959279b5e3cd451fee54273512c.png
    [file_type] => image/png
    [file_path] => I:/wamp/www/e-commerce/sources/images/
    [full_path] => I:/wamp/www/e-commerce/sources/images/2385b959279b5e3cd451fee54273512c.png
    [raw_name] => 2385b959279b5e3cd451fee54273512c
    [orig_name] => 1269770869_Art_Artdesigner.lv_.png
    [file_ext] => .png
    [file_size] => 15.43
    [is_image] => 1
    [image_width] => 113
    [image_height] => 128
    [image_type] => png
    [image_size_str] => width="113" height="128"
)

this is the function helper

function multiple_upload($name = 'userfile', $upload_dir = 'sources/images/', $allowed_types = 'gif|jpg|jpeg|jpe|png', $size)
    {
        $CI =& get_instance();

        $config['upload_path']   = realpath($upload_dir);
        $config['allowed_types'] = $allowed_types;
        $config['max_size']      = $size;
        $config['overwrite']     = FALSE;
        $config['encrypt_name']  = TRUE;

            $ffiles = $CI->upload->data();

            echo "<pre>";
            print_r($ffiles);
            echo "</pre>";
            $CI->upload->initialize($config);
            $errors = FALSE;

            if(!$CI->upload->do_upload($name))://I believe this is causing the problem but I'm new to codeigniter so no idea where to look for errors
                $errors = TRUE;
            else:
                // Build a file array from all uploaded files
                $files = $CI->upload->data();
            endif;


            // There was errors, we have to delete the uploaded files
            if($errors):                   
                @unlink($files['full_path']);
                return false;
            else:
                return $files;
            endif;

    }//end of multiple_upload()

and this is the code in my controller

if(!$s_thumb = multiple_upload('small_thumb', 'sources/images/', 'gif|jpg|jpeg|jpe|png', 1024)): //http://www.matisse.net/bitcalc/
    $data['feedback'] = '<div class="error">Could not upload the small thumbnail!</div>';
    $error = TRUE;
endif;
if(!$main_file = multiple_upload('main_file', 'sources/items/', 'zip', 307200)):
    $data['feedback'] = '<div class="error">Could not upload the main file!</div>';
    $error = TRUE;
endif;

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about zip