Code:
<?php
//===add below line to config.php. path must be end with trailing slash
$config['base_path']='C://wamp/www/demo/upload/';
///===put the code in controller or model
$CI =& get_instance();
$base_path = $CI->config->slash_item('base_path');
$this->load->library('upload');
$rand=rand(0,100000);
for($i=0;$i<count($_FILES['file_up']['name']);$i++)
{
$_FILES['userfile']['name'] = $_FILES['file_up']['name'][$i];
$_FILES['userfile']['type'] = $_FILES['file_up']['type'][$i];
$_FILES['userfile']['tmp_name'] = $_FILES['file_up']['tmp_name'][$i];
$_FILES['userfile']['error'] = $_FILES['file_up']['error'][$i];
$_FILES['userfile']['size'] = $_FILES['file_up']['size'][$i];
$config['file_name'] = $rand.'user_'.$i;
$config['upload_path'] = 'upload/orig/';
$config['allowed_types'] = 'jpg|jpeg|gif|png|bmp';
$this->upload->initialize($config);
if (!$this->upload->do_upload()) {
$error = $this->upload->display_errors();
}
$picture = $this->upload->data();
$this->load->library('image_lib');
$this->image_lib->clear();
$this->image_lib->initialize(array(
'image_library' => 'gd2',
'source_image' => $base_path.'upload/orig/'.$picture['file_name'],
'new_image' => $base_path.'upload/thumb/'.$picture['file_name'],
'maintain_ratio' => FALSE,
'quality' => '100%',
'width' => 602,
'height' => 237
));
if(!$this->image_lib->resize()){
$error = $this->image_lib->display_errors();
}
}
?>