"imagecopy() expects parameter 1 to be resource, boolean given" Codeigniter - codeigniter

I'm calling do_upload_img() function only if there is any input value, like this:
function xxx()
{
if($_FILES['portfolioimg']['size'])
{
$portfolioimg = $this->do_upload_img();
}
// remaining code.......
}
do_upload_img() function
function do_upload_img()
{
if(isset($_FILES['portfolioimg']['size']) != 0){
$name_array = array();
$files = $_FILES;
$cpt = count($_FILES['portfolioimg']['name']);
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './assets/img/watermark.png';
$config['quality'] = 50;
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
for($i=0; $i<=$cpt-1; $i++)
{
$_FILES['userfile']['name']= $files['portfolioimg']['name'][$i];
$_FILES['userfile']['type']= $files['portfolioimg']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['portfolioimg']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['portfolioimg']['error'][$i];
$_FILES['userfile']['size']= $files['portfolioimg']['size'][$i];
$imgnam = rand(10,1000000);
$ext = pathinfo($files['portfolioimg']['name'][$i], PATHINFO_EXTENSION);
if($this->upload->initialize($this->set_upload_options($imgnam))){
$data = $this->upload->do_upload();
$config['source_image'] = './assets/portfolio_img/' . 'Soooo_'.$imgnam.'.'.$ext;
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$name_array[] = $this->upload->data('file_name');
} else {
$this->session->set_flashdata('falsemsg','Only jpg, jpeg, png files are allowed to be uploaded.');
}
}
return $name_array;
}else{
return false;
}
}
View
<input class="fileUpload" accept="image/jpeg, image/jpg, image/png, image/gif" name="portfolioimg[]" type="file" value="" data-msg-accept="Please upload only jpg, jpeg, png and gif file">
If I run this xxx() function and if the portfolioimg input field have no value then it showing a warning message like this:
A PHP Error was encountered
Severity: Warning
Message: imagecopy() expects parameter 1 to be resource, boolean
given
Filename: libraries/Image_lib.php
Line Number: 1217
And also if I use error_reporting(0), still the warning is displaying.

Related

Saving animated gif with image intervention

I am trying to upload animated gif as user avatar. These images are converted to base64 through javascript and then are uploaded using image intervention.
$img = Image::make(file_get_contents($file));
$mime = $img->mime();
if ($mime == 'image/jpeg')
$ext= '.jpg';
elseif ($mime == 'image/png')
$ext= '.png';
elseif ($mime == 'image/gif')
$ext= '.gif';
elseif($mime == 'image/x-icon')
$ext = '.ico';
elseif($mime == 'image/bmp')
$ext = '.bmp';
else {
$ext = '.jpg';
}
$name = time().$ext;
$path = public_path("images/$controller");
File::isDirectory($path) or File::makeDirectory($path);
if(property_exists($field, 'size') && !$ext=='.gif') {
$field->size = explode('*',$field->size);
if($img->resize($field->size[0], $field->size[1])->save("$path/$name")) {
$data[$key] = $name;
} else {
$data[$key] = null;
}
} else {
if($img->save("$path/$name")) {
$data[$key] = $name;
} else {
$data[$key] = null;
}
}
But, those images lose animation after upload. I don't know what to do. How to not lose animation?
Javascript code:
reader.onload = function(e) {
var src = e.target.result;
var name = file.name;
var type = file.type;
var img = "<img src='"+src+"' class='img-fluid mx-auto' alt='image'>";
$('.card_group_'+field+' .previewContainer_'+count+' .file-loading').remove();
$('.card_group_'+field+' .previewContainer_'+count+' .imagePreview').append(img);
$('.card_group_'+field+' .previewContainer_'+count+' .card-header').append(name);
var input = "input[name='"+field+"']";
var added = $(input).val();
if(added == '') {
$(input).val(src);
} else {
$(input).val(added+';'+src);
}
}
reader.readAsDataURL(file);
For now, you can use another function to save when it is a gif, and keep using others from the library.
if ($file->getClientOriginalExtension() == 'gif') {
copy($file->getRealPath(), $destination);
}
else {
$image->save($destination);
}
$width = $image->width();
$height = $image->height();
$image->destroy();
Credits to: https://github.com/Intervention/image/issues/176#issuecomment-58863939

uploading multiple image in codeigniter using same input

views
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="userfile[]" size="40" multiple/>
<input type="submit" name="submit" value="Upload">
</form>
controller
public function image()
{
$data['error'] = '';
$this->load->model('StackM');
if(isset($_POST['submit']))
{
$data['update_pass_error_msg'] = $this->StackM->add_multiple_image();
}
$this->load->view('stack_view');
}
Model
public function add_multiple_image(){
if((!empty($_FILES['f2']['name'])))
{
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$files = $_FILES;
if ($files['f2']['name'][0] == '' )
{
# code...
return "Select a file to upload";
}
else
{
$mum_files = count($files['f2']);
for($i=0; $i<$mum_files; $i++)
{
if ( isset($files['f2']['name'][$i]) )
{
$config['file_name'] = time().'-'.$files['f2']['name'][$i];
$this->load->library('upload', $config);
$_FILES['f2']['name']= $files['f2']['name']["$i"];
$_FILES['f2']['type']= $files['f2']['type']["$i"];
$_FILES['f2']['tmp_name']= $files['f2']['tmp_name']["$i"];
$_FILES['f2']['error']= $files['f2']['error']["$i"];
$_FILES['f2']['size']= $files['f2']['size']["$i"];
$filename = rand().'-'.$_FILES['f2']['name'];
if (!empty($this->upload->do_upload('f2')))
{
$dataInfo[] = $this->upload->data();
$all_imgs = '';
if ( count($dataInfo) > 0) {
# code...
foreach ($dataInfo as $info) {
# code...
$all_imgs .= $info['file_name'];
$all_imgs .= ',';
}
}
}
}
}
}
}
else{
$all_imgs = "";
}
}
}
else{
$all_imgs = $this->session->userdata('image');
}
$this->db->insert('table_name', $all_imgs);
The problem I am facing in this code is Think suppose if I am adding 7 images, but it's showing only 5 images in database it's not taking more then five and also I want to know while editing the form if I don't want to change the image then it should remain same image so i have stored the old image in session and checking if it is empty then only it should session variable .
But In my code if I will not upload new one If I keep old image as then it will save blank
To avoid the offset error, inside of for loop you need to check if that array index is set or not:
Here I have a demo code to upload multiple files in CodeIgniter:
views/stack_view.php
<?php if ($this->session->flashdata('status')) { ?>
<h5><?=$this->session->flashdata('status')?>: <?=$this->session->flashdata('message')?></h5>
<?php } ?>
<?=form_open_multipart('stack', array('id' => 'my_id'))?>
<input type="file" name="userfile[]" size="40" multiple/>
<input type="submit" name="submit" value="Upload">
<?=form_close()?>
controllers/Stack.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Stack extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper(array('form', 'url'));
}
public function index()
{
if ($this->input->post('submit')) {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$files = $_FILES;
if ($files['userfile']['name'][0] == '' ) {
# code...
$this->session->set_flashdata('status', 'error');
$this->session->set_flashdata('message', "Select a file to upload");
}
else
{
$mum_files = count($files['userfile']);
$dataInfo = array();
for($i=0; $i<$mum_files; $i++)
{
if ( isset($files['userfile']['name'][$i]) ) {
$config['file_name'] = time().'-'.$files['userfile']['name'][$i];
$this->load->library('upload', $config);
$_FILES['userfile']['name']= $files['userfile']['name']["$i"];
$_FILES['userfile']['type']= $files['userfile']['type']["$i"];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name']["$i"];
$_FILES['userfile']['error']= $files['userfile']['error']["$i"];
$_FILES['userfile']['size']= $files['userfile']['size']["$i"];
$filename = rand().'-'.$_FILES['userfile']['name'];
if ( ! $this->upload->do_upload('userfile'))
{
$error_message = $this->upload->display_errors();
$this->session->set_flashdata('status', 'error');
$this->session->set_flashdata('message', "$error_message");
}
else
{
//$data = array('upload_data' => $this->upload->data());
$this->session->set_flashdata('status', 'success');
$this->session->set_flashdata('message', "Files upload is success");
}
$dataInfo[] = $this->upload->data(); //all the info about the uploaded files are stored in this array
}
}
//here you can insert all the info about uploaded file into database using $dataInfo
$all_imgs = '';
if ( count($dataInfo) > 0) {
# code...
foreach ($dataInfo as $info) {
# code...
$all_imgs .= $info['file_name'];
$all_imgs .= ',';
}
}
$insert_data = array(
'your_column_name' => rtrim($all_imgs,",")
);
$this->db->insert('your_table_name', $insert_data);
}
}
$this->load->view('stack_view');
}
}
Try this script and I hope you will get some help from this.
This is working script try to upload it
public function upload()
{
$this->load->library('session');
if ( ! empty($_FILES))
{
$config['upload_path'] = "assets/uploads/";
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = 5120; //limit only 5 Mb
$this->load->library('upload');
$files = $_FILES;;
$number_of_files = count($_FILES['files']['name']);
$errors = 0;
$myname = $this->input->post('ad_title');
for ($i = 0; $i < $number_of_files; $i++)
{
//$randVal = rand(450,4550).time('d-y-m');
$filename = basename($files['files']['name'][$i]);
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$new = md5($filename.''.time('d-y-m')).'.'.$extension;
$_FILES['files']['name'] = $new; //$files['files']['name'][$i];
$_FILES['files']['type'] = $files['files']['type'][$i];
$_FILES['files']['tmp_name'] = $files['files']['tmp_name'][$i];
$_FILES['files']['error'] = $files['files']['error'][$i];
$_FILES['files']['size'] = $files['files']['size'][$i];
$image = array('upload_data' => $this->upload->data());
$image_name = $_FILES['files']['name'];
$ip = $this->input->ip_address();
$this->session->set_userdata("userIP",$ip);
//$this->session->unset_userdata("userIP");
$Dval = array(
"filename" => $image_name,
"ip" => $this->input->ip_address()
);
$this->member_model->tmp_image($Dval);
$this->upload->initialize($config);
if ( $this->upload->do_upload("files"))
{
$errors++;
$data = $this->upload->data();
echo json_encode($data['file_name']);
//code is for thumbnail and watermark on images
//$this->watermark($data['full_path']);
//$myPathfT = $config1['upload_path'] = "./assets/thumbs/".$aDir;
//mkdir($myPathfT);b
$config1 = array();
$config1['image_library'] = 'gd2';
$config1['source_image'] = $data['full_path'];
$config1['new_image'] = 'assets/uploads/thumbs/';
$config1['create_thumb'] = false;
$config1['quality'] = 50;
$config1['height'] = 150;
$config1['width'] = 150;
$this->load->library('image_lib',$config1);
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$this->image_lib->clear();
}
}
if ($errors > 0)
{
//echo "Data Transferred";
}
}
elseif ($this->input->post('file_to_remove'))
{
$aDir = $this->session->userdata('Dir');
$file_to_remove = $this->input->post('file_to_remove');
unlink("./assets/mainFilesData/$aDir/" . $file_to_remove);
$array = $this->session->userdata('photo');
$dataF = array_diff($array, array($file_to_remove));
$this->session->set_userdata('photo',$dataF);
}
else
{
$this->listFiles();
}
}

Display all subfolders of folder in CodeIgniter

I am trying to display my uploaded content in my view page.
I have uploaded some files to my assets folder. In this the applicant (here) has an id, and uploading documents also have an id. During uploading these document ids are inserted in db with commas.
The uploaded path is ./assets/uploads/applicant_id/document_id.
I want to display the all files from this path. Problem is that when l have uploaded a document, and display only its (last uploaded) document files .
function index()
{
$application_id=$this->session->userdata('application_id');
$this->load->helper('directory');
$document_details = $this->home_model->get_document_details();
$$document_ids = $this->home_model->get_evidence_ids($application_id);
$$document_id= $evidence_ids->applicant_evidence_id;
$document= explode(',',$evidence_id);
for($i=0; $i < count($evidence); $i++)
{
$uploaded_files = array();
$uploaded_files = directory_map('./application/assets/uploads/'.$application_id.'/'.$document_id[$i]);
}
$data=array(
'document'=>$document,
'document_details'=>$document_details,
'page_name'=>'Home',
'dashboard_index'=>1,
'uploaded_files' =>$uploaded_files,
'application_id'=>$application_id,
'head_extra'=>'<link rel="stylesheet" type="text/css" href="'.base_url().'application/assets/css/home.css"> ',
'footer_extra'=>'',
);
$this->load->view('header',$data);
$this->load->view('index',$data);
$this->load->view('footer',$data);
}
function do_upload()
{
$evidence_id = $_POST['document_id'];
$application_id=$this->session->userdata('application_id');
$this->load->library('upload');
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($this->set_upload_options($document_id,$application_id));
$this->upload->do_upload();
}
$evidence = $this->home_model->insert_evidence($application_id,$document_id);
$success_message = "Document Uploaded.";
$this->session->set_flashdata('success_message',$success_message);
redirect(base_url().'home','refresh');
}
private function set_upload_options($document_id,$application_id)
{
if(!is_dir('./application/assets/uploads/'.$application_id.'/'.$document_id))
{
mkdir('./application/assets/uploads/'.$application_id.'/'.$document_id, 0777, TRUE);
}
$config = array();
$config['upload_path'] = './application/assets/uploads/'.$application_id.'/'.$document_id;
$config['allowed_types'] = 'jpg|png|bmp|jpeg|gif|vnd.ms-excel|vnd.openxmlformats-officedocument.spreadsheetml.sheet|csv|pdf';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
return $config;
}
view
<div class="portal-body">
<?php $file_count = count($uploaded_files);
for($i=0;$i<$file_count;$i++)
{ ?>
<p><?php echo $uploaded_files[$i]; ?></p>
<?php } ?>
</div>
First get the images from database
For ex.
$images = image1,image2,image3;
$newImages = explode(',',$images);
Now use foreach loop
foreach($newImages as $img)
{
//check for file type
$name = $img;
$info = new SplFileInfo($name);
$extension = $info->getExtension();
//echo $extension;
if($extension == "jpg" || $extension == "png" || $extension == "gif" || $extension == "jpeg") {
<img src="<?php echo base_url('your file location/.$img');?>">;
}else{
show your file here
}
}
For more read this tutorial
http://w3code.in/2015/09/upload-file-using-codeigniter/

i have a working multiple upload (document and image) CODEIGNITER

I have made a working multiple upload in codeigniter but I'm having a problem on how am I gonna insert the file names of those files on two tables (documents and images table) which these two tables have two the same column name (ID, name). is there way that i could disjunct or compart my code for uploading image and doc. because I united them in one function.
here is my CODE. it is working.
VIEW
<?php echo form_open_multipart('test'); ?>
<label>Images</label>
<input type='file' multiple='multiple' name='userfile[]'>
<label>Documents</label>
<input type='file' multiple='multiple' name='userfile[]'>
<?php echo form_submit('submit', 'Upload them files!') ?>
CONTROLLER
function index()
{
if (isset($_POST['submit']))
{
$this->load->library('upload');
//$this->uploadfile($_FILES['userfile']);
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$filename = $_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
$this->upload->data();
}
}
$this->load->view("test");
}
private function set_upload_options()
{
// upload an image and document options
$config = array();
$config['upload_path'] = './upload_documents/';
$config['allowed_types'] = 'jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG|pdf|doc|docx|xls|xlsx';
$config['max_size'] = '0'; // 0 = no file size limit
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['overwrite'] = TRUE;
return $config;
}
These codes are working and it is able to transfer all the files on my desired path.
but I was wondering on making the MODEL, how am I gonna identify the file type as you seen my codes above I passed the name of the file on a variable "$filename". If you use print_r($filename), you'll see all the file name and it's file extension. Those names is the one that I will insert to my two tables accordingly to their type of file.
Is there any code for CodeIgniter or PHP code that I will use to identify the file type and pass it to the model with two function like upload_image or upload_docu? Help please.
so here it is..
CONTROLLER
function index()
{
if (isset($_POST['submit']))
{
$this->load->library('upload');
//$this->uploadfile($_FILES['userfile']);
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
$this->upload->data();
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$img_ext_chk = array('jpg','png','gif','jpeg','JPG','PNG', 'GIF', 'JPEG');
if (in_array($ext,$img_ext_chk))
{
$this->asset->add_image($filename);
}
else
{
$this->asset->add_document($filename);
}
}
}
}
and to your MODEL
public function add_image($filename)
{
$data = array ('images' => $filename);
$this->db->insert('asset_images', $data);
}
public function add_document($filename)
{
$data = array ('documents' => $filename);
$this->db->insert('asset_documents', $data);
}

Uploading an image in codeigniter

I am trying to upload an image,create thumbnail but i get an error.
Here is my controller.
<?php
class Upload extends Controller {
function Upload()
{
parent::Controller();
$this->load->helper(array('form','url','file'));
}
function index()
{
$this->load->view('upload_form'); //Upload Form
}
function picupload()
{
//Load Model
$this->load->model('Process_image');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048'; //2 meg
$this->load->library('upload');
foreach($_FILES as $key => $value)
{
if( ! empty($key['name']))
{
$this->upload->initialize($config);
if ( ! $this->upload->do_upload($key))
{
$errors[] = $this->upload->display_errors();
}
else
{
$this->Process_image->process_pic();
}
}
}
$data['success'] = 'Thank You, Files Upladed!';
$this->load->view('upload_success', $data); //Picture Upload View
}
}
?>
My model:
<?php
class Process_image extends Model {
function Process_image()
{
parent::Model();
$this->load->library('image_lib');
//Generate random Activation code
function generate_code($length = 10){
if ($length <= 0)
{
return false;
}
$code = "";
$chars = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
srand((double)microtime() * 1000000);
for ($i = 0; $i < $length; $i++)
{
$code = $code . substr($chars, rand() % strlen($chars), 1);
}
return $code;
}
}
function process_pic()
{
//Connect to database
$this->load->database();
//Get File Data Info
$uploads = array($this->upload->data());
$this->load->library('image_lib');
//Move Files To User Folder
foreach($uploads as $key[] => $value)
{
//Gen Random code for new file name
$randomcode = generate_code(12);
$newimagename = $randomcode.$value['file_ext'];
//Creat Thumbnail
$config['image_library'] = 'GD2';
$config['source_image'] = $value['full_path'];
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_tn';
$config['master_dim'] = 'width';
$config['quality'] = 75;
$config['maintain_ratio'] = TRUE;
$config['width'] = 175;
$config['height'] = 175;
$config['new_image'] = '/pictures/'.$newimagename;
//$this->image_lib->clear();
$this->image_lib->initialize($config);
//$this->load->library('image_lib', $config);
$this->image_lib->resize();
//Move Uploaded Files with NEW Random name
rename($value['full_path'],'/pictures/'.$newimagename);
//Make Some Variables for Database
$imagename = $newimagename;
$thumbnail = $randomcode.'_tn'.$value['file_ext'];
$filesize = $value['file_size'];
$width = $value['image_width'];
$height = $value['image_height'];
$timestamp = time();
//Add Pic Info To Database
$this->db->set('imagename', $imagename);
$this->db->set('thumbnail', $thumbnail);
$this->db->set('filesize', $filesize);
$this->db->set('width', $width);
$this->db->set('height', $height);
$this->db->set('timestamp', $timestamp);
//Insert Info Into Database
$this->db->insert('pictures');
}
}
}
?>
The error:
A PHP Error was encountered
Severity: Warning
Message: rename(C:/wamp/www/uploads/Heaven_Clouds.jpg,/pictures/kFttl7lpE7Rk.jpg) [function.rename]: No such file or directory
Filename: models/Process_image.php
Line Number: 68
This is line 68:
rename($value['full_path'],'/pictures/'.$newimagename);
Remove the "/" before "picutres" in
rename($value['full_path'],'/pictures/'.$newimagename);
It wanna say that you want put your renamed file in a directory named "pictures" placed at the root of an Unix file system, then you're obviously in a Windows system and you do not seem to have a "pictures" directory at the root of your disk.
result :
rename($value['full_path'],'pictures/'.$newimagename);
This is a very simple script taken partly from the CI Docs:
$config['upload_path'] = 'uploads/cgm/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
$configThumb = array();
$configThumb['image_library'] = 'gd2';
$configThumb['source_image'] = '';
$configThumb['create_thumb'] = TRUE;
$configThumb['maintain_ratio'] = TRUE;
$configThumb['width'] = 100;
$configThumb['height'] = 120;
$this->load->library('image_lib');
for($i = 1; $i < 6; $i++) {
$upload = $this->upload->do_upload('file'.$i);
if($upload === FALSE) continue;
$data = $this->upload->data();
$uploadedFiles[$i] = $data;
$imgName = $this->pictures_m->addPicture(array('listing_id' => $listing_id, 'ext' => $data['file_ext'], 'picture_name' => $this->input->post('file'.$i.'name')));
if($data['is_image'] == 1) {
$configThumb['source_image'] = $data['full_path'];
$configThumb['new_image'] = $data['file_path'].$imgName.$data['file_ext'];
$this->image_lib->initialize($configThumb);
$this->image_lib->resize();
}
rename($data['full_path'], $data['file_path'].$imgName.$data['file_ext']);
}
this will take 5 images, but if you only have one, you can just change the for loop.
i had the same problem but, in my scenario i've to only upload the array of files so i did some small changes to the library 'Upload.php'
view
<form encrypt="multipart/form-data" ...>
<input type="file" name="your_name[]" />
<input type="file" name="your_name[]" />
<input type="submit" />
</form>
controller
for($i = 0; $i < count($_FILES['your_name']['name']); $i++) {
$config['upload_path'] = 'your upload path';
$this->upload->initialize($config);
$this->upload->do_upload('listing_images', $i);
endfor;
if you have single file to upload then duplicate the function in system/libraries/Upload.php
function do_upload($field) to function do_upload_array($field, $i)
put [$i] index on lines 160, 162, 196, 197
and
function _file_mime_type($_FILES[$field]) to function _file_mime_type_array($_FILES[$field], $i)
and put [$i] index on lines 1026, 1043, 1057 and 1065
thats it...
your file array will upload easily now....

Resources