Welcome Guest, Not a member yet? Register   Sign In
Multi file upload help
#1

[eluser]steviez[/eluser]
Hi,

I am trying to make codeigniter upload multiple files at once but all i get is errors. My code is this:

Code:
function do_upload()
    {
        // set upload set id
        $set_id = md5(rand(1, 7) . rand(1, 4) . rand(1, 6));
        
        // check to make sure upload form was posted
        if($this->input->post('task') == "doUpload")
        {
            // create upload directory
            if(!@mkdir($this->core->site_config['upload_path'] . $set_id . "/"))
            {
                // set flash message
                $this->session->set_flashdata('upload_error', 'Failed to create upload directory.');
                
                // redirect
                redirect($this->core->site_config['site_url'], 301);                
            }
            
            // if new upload directory exists add index.html file
            if(is_dir($this->core->site_config['upload_path'] . $set_id . "/"))
            {
                $fh = fopen($this->core->site_config['upload_path'] . $set_id . "/index.html", "w");
                fclose($fh);
            }
            
            // create the config for upload library
            $config['upload_path'] = $this->core->site_config['upload_path'] . $set_id . "/";
            $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
            $config['max_size']  = $this->core->site_config['max_file_size']; // in KB
            $config['max_width']  = '0';
            $config['max_height']  = '0';
            
            // load the upload library
            $this->load->library('upload', $config);
            
            // create the config for image library
            $configThumb = array();
            $configThumb['image_library'] = 'gd2';
            $configThumb['source_image'] = '';
            $configThumb['create_thumb'] = TRUE;
            $configThumb['maintain_ratio'] = TRUE;
            $configThumb['width'] = 120;
            $configThumb['height'] = 120;
            
            // load the image library
            $this->load->library('image_lib');
            
            // loop over uploaded image files
            while(list($key, $value) = each($_FILES['image']['name']))
            {
                // handle the file upload
                $upload = $this->upload->do_upload($key);
                
                // file failed to upload - continue
                //if($upload === FALSE) continue;
                
                // get the data about the file
                $data = $this->upload->data();
                
                $uploadedFiles[$key] = $data;
                
                // if the file is an image - create a thumbnail
                if($data['is_image'] == 1)
                {
                    $configThumb['source_image'] = $data['full_path'];
                    $this->image_lib->initialize($configThumb);
                    $this->image_lib->resize();
                }  
                
                echo $this->upload->data();
                
                echo $this->upload->display_errors();
            }
                        
        }
    }

but all i get when upload is complete is:

Quote:Array

You did not select a file to upload.
Array

You did not select a file to upload.

You did not select a file to upload.
Array

You did not select a file to upload.

You did not select a file to upload.

You did not select a file to upload.
Array

You did not select a file to upload.

You did not select a file to upload.

You did not select a file to upload.

You did not select a file to upload.

any ideas?
#2

[eluser]Bigil Michael[/eluser]
this code will help u.this code is for uploading 6 images at a time

controller

function manage_image(){

if($this->input->post('Submit')){
for($i=1;$i<=6;$i++)
{
if($_FILES['photo_'.$i]['name']!=''){
//upload thumbnail
$config = array();
$config['upload_path'] = absolute_path().'flashimages/';
$config['allowed_types'] = 'png';
$config['file_name'] = '0'.$i;
$config['max_size'] = '1024';
$config['overwrite'] = 'TRUE';
$this->load->library('upload');
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('photo_'.$i))
{
$data['alert'] = $this->upload->display_errors();
$this->load->view('admin/homepage/add_image', $data);
}
else
{
$upload_data = $this->upload->data();

$filename = $upload_data['file_name'];

$width = $upload_data['image_width'];
$height = $upload_data['image_height'];
$config1 = array();
$this->load->library('image_lib');
$config1['source_image'] = absolute_path().'flashimages/'.$filename;

if($width>449){
//resize image
$sizes = array('width' => $width, 'height' => $height, 'new_width' => 449, 'new_height' => 271);
$newsize = array();
$newsize = $this->image_lib->size_calculator($sizes);
$config1['maintain_ratio'] = FALSE;
$config1['width'] = $newsize['new_width'];
$config1['height'] = $newsize['new_height'];
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$this->image_lib->clear();
}
$config1['maintain_ratio'] = FALSE;
$config1['width'] = 350;
$config1['height'] = 392;
$config1['create_thumb'] = TRUE;
$config1['thumb_marker'] = 'thumb_';
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$this->Homepage_model->save_image('photo_'.$i,$filename);
$data['alert'] = 'image uploaded';
}
}
}


}else{
//call view here
}
}

model

function save_image($field,$filename=''){
$cid=1;
if($filename!=''){
$data[$field] = $filename;
}
$this->db->where('id',$cid);
$this->db->update('home',$data);
}




Theme © iAndrew 2016 - Forum software by © MyBB