I have a helper function in codeigniter php where I can use helper like so load_controller('column_left', 'index'); for example "column_left" is the file and class name.

How ever that works fine but I would like to be able to type a folder name in load_controller('some_folder/some_class', 'index'); and it would detect controller.

Question How can I make it so if I type a name of a subfolder in controllers then will pick folder and filename up.

<?php

function load_controller($controller, $method = 'index', $params = '') {

    require_once (APPPATH . 'controllers/' . $controller . '.php'); // Need to sill have as backup

    $controller = new $controller();

    return $controller->$method($params);
}

I would like to know if possible to convert this to the codeigniter active record way using this->db->join etc.

What's the best. It works fine with the code I got but would like to make it work with codeigniter db active records.

http://www.codeigniter.com/userguide2/database/active_record.html

public function get_category($category_id) {
        $language_id = $this->check_language();

        $query = $this->db->query("SELECT DISTINCT *, 
                (SELECT GROUP_CONCAT(cd1.name ORDER BY level SEPARATOR '&nbsp;&nbsp;&gt;&nbsp;&nbsp;') 
                    FROM " . $this->db->dbprefix . "category_path cp LEFT JOIN " . $this->db->dbprefix . "
                    category_description cd1 ON (cp.path_id = cd1.category_id AND cp.category_id != cp.path_id) 
                    WHERE cp.category_id = c.category_id 
                    AND cd1.language_id = '" . (int)$language_id . "' 
                    GROUP BY cp.category_id) 
                    AS path 
                    FROM " . $this->db->dbprefix . "category c 
                    LEFT JOIN " . $this->db->dbprefix . "category_description cd2 
                    ON (c.category_id = cd2.category_id) 
                    WHERE c.category_id = '" . (int)$category_id . "' 
                    AND cd2.language_id = '" . (int)$language_id . "'
                ");

        return $query->row_array();
    }

I have solved issue I now use $this->get_categories($category['category_id']); for the child links in controller. When loaded by model function was not working so updated with the function on controller and now working.

I tried that no luck very strange but most lilkey a simple fix.

On my controller I have a variable called 'name' => $child['name'], for my drop down menu.

The problem I am having is that in the child dropdown menu it still shows parent name.

I am trying to make it so if parent_id name is equal 0 then will not show in dropdown child links.

Why is it still showing parent name in dropdown child links

Controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends MX_Controller {

    public function index() {
        $this->load->model('admin/catalog/model_catalog_category');

        $data['categories'] = array();

        $categories = $this->get_categories(0);

        foreach ($categories as $category) {
            if ($category['top']) {

                $children = $this->model_catalog_category->get_categories($category['category_id']);

                foreach ($children as $child) {
                    // Level 2
                    $children_data[] = array(
                        'name' => $child['name'],
                        'href' => site_url('admin/test') .'/'. strtolower($category['name']) .'/'. strtolower($child['name'])
                    );
                }

                // Level 1
                $data['categories'][] = array(
                    'name' => $category['name'],
                    'children' => $children_data,
                    'column'   => $category['column'] ? $category['column'] : 1,
                    'href' => site_url('admin/test') .'/'. strtolower($category['name'])
                );
            }
        }

        $this->load->view('template/test/test_category_view', $data);
    }

    public function get_categories($parent_id = 0) {
        $this->db->where('parent_id', $parent_id);
        $query = $this->db->get('category');
        if ($query->num_rows() > 0) {
            return $query->result_array();
        } else {
            return false;
        }
    }
}

View

<?php if ($categories) { ?>
<div class="container">
    <nav id="menu" class="navbar">
    <div class="navbar-header">
    <span id="category" class="visible-xs">Menu</span>
        <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
    </div>
    <div class="collapse navbar-collapse navbar-ex1-collapse">
        <ul class="nav navbar-nav">
            <?php foreach ($categories as $category) { ?>

                <?php if ($category['children']) { ?>

                <li class="dropdown">
                <a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown">
                <?php echo $category['name']; ?>
                </a>

                <div class="dropdown-menu">

                    <div class="dropdown-inner">

                        <?php foreach (array_chunk($category['children'], ceil(count($category['children']) / ...

When I view my list in my admin I would like to be able to make sure the controller name is sorted asc

Currently it does not sort alphabetically

 'name' => ucwords(str_replace('_', ' ', $controller)), 

Function

public function index() {
    $data['title'] = "User Group Permissions";

    $controller_files = $this->get_installed_permissions('name'); 

    $data['controller_files'] = array();

    $files = glob(FCPATH . 'application/modules/admin/controllers/*/*.php');

    if ($files) {

        foreach ($files as $file) {

            $controller =  basename(strtolower($file), '.php');

            $modules = $this->get_permissions_by_controller($controller);

            $module_data = array();

            foreach ($modules as $module) {
                $module_data[] = array(
                    'user_group_id' => $module['user_group_id'],
                    'name' => ucwords(str_replace('_', ' ', $controller) . ' &gt; ' . $module['name']),
                    'edit' => site_url('admin/extension/permissions/update' .'/'. $controller .'/'. $module['user_group_id']),
                    'delete' => '' 
                );
            }

            $data['controller_files'][] = array(
                'name' => ucwords(str_replace('_', ' ', $controller)),
                'controller' => $controller,
                'module'    => $module_data,
                'install' => site_url('admin/extension/permissions/install') .'/'.$controller,
                'installed' => in_array($controller, $controller_files)
            );

        }
    }

    $this->load->view('template/extension/extension_permissions', $data);
}

I tried that earlier and same result. Very strange. Even though I have permission to edit. Still throughs error.

When I or user logs on it checks what permissions it has. And then on a form if has not got permission throws error.

Example:

<?php

class Users_groups extends CI_Controller {

public function update() {
   if (($this->input->server('REQUEST_METHOD') == 'POST') && $this->validateForm()) {
      // Modal stuff
   }
}

public function index() {
 // form content
}

public function validateForm() {
    if (!$this->user_auth->hasPermission('modify', 'user/Users_groups')) {
        $this->error['warning'] = 'You do not have permission to modify';
    }

    return !$this->error;
}

}

When I submit form it should let me edit and save but for some reason this

if(isset($value))  {return $value==$this->permission[$key];}

is not working so when I submit my form it throw error.

Severity: Notice

Message: Undefined index: modify

Filename: libraries/User_auth.php

Line Number: 65

Line 65 is this

if(isset($value))  {return $value==$this->permission[$key];}

I do not know why not working way it should I am confused.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_auth {

private $permission = array();
private $user_id;
private $username;

public function __construct() {
    $this->CI =& get_instance();
    $this->CI->load->model('admin/user/model_user_user');
    $this->CI->load->library('session');
}

/**
 * @return bool
 */
public function login() {

    $this->CI->db->where('username', $this->CI->input->post('username'));
    $user_query = $this->CI->db->get('user');

    if ($user_query->num_rows() > 0) {

        $row = $user_query->row();

        $this->CI->db->select('permission');
        $this->CI->db->from($this->CI->db->dbprefix .'user_group');
        $this->CI->db->where('user_group_id', $row->user_group_id);
        $user_group_query = $this->CI->db->get();

        if ($user_group_query->num_rows() > 0) {

            $permissions = unserialize($user_group_query->row('permission'));

            if (!is_array($permissions)) {
                foreach ($permissions as $key => $value) {
                    $this->permission[$key] = $value;
                }
            }

        } else {
            return false;
        }

        if ($this->CI->model_user_user->check_password($this->CI->input->post('password'), $user_query->row('password'))) {
            return true;
        } else {
            return false;
        }

    } else {
        return false;
    }

}

/**
 * ...

I have made a library class in php which can get data from my database table settings.

I can get information if it is not serialized.

But I would like to know on my get function what would be best method to be able to return unserialise information just incase it is serialized.

<?php

class Settings {

private $data = array();

public function __construct() {
$this->CI =& get_instance();      
}

public function get($key = NULL) {
if ($key != NULL) {
$value = $this->get_where($key);
return $value;
} else {
return FALSE;
}
}

public function get_where($key = NULL) {
if ($key != NULL) {
$store_id = $this->store_id();
$result = $this->CI->db->get_where($this->CI->db->dbprefix . 'setting', array('store_id' => $store_id, 'group' => 'config', 'key' => $key));
if ($result != FALSE AND $result->num_rows() > 0) { 
$data = $result->result_array();
return $data[0]['value'];
} else {
return FALSE;
}
} else {
return FALSE;
} 
}

public function store_id() {
$store_id = $this->CI->uri->segment(5);
if ($store_id !== TRUE) {
return $store_id;
} else {
return FALSE;
}
}

}

@pixelsoul do you have a example. All ways willing to try new and better ways.

I have found my own solution deleting multiple selected files to me a while but here it is

public function delete() {
        $path[] =  FCPATH . 'application/modules/admin/controllers/module' .'/'. $this->uri->segment(5).'.php';
        $path[] =  FCPATH . 'application/modules/admin/language'.'/' .'english' .'/'. 'module/'. $this->uri->segment(5).'_lang.php';
        $path[] =  FCPATH . 'application/modules/admin/views/template/module' .'/'. $this->uri->segment(5).'.tpl';

        foreach ($path as $file) {

        if (unlink(realpath($file))) {
            echo "deleted file" .' '. "<br/><br/>"$file;
        } else {
            echo "did not delete" .' '. $file;
        }

        }
    }

I have three files which when i click on delete should be removed. How am I able to use the unlink and realpath for my multiple files?

public function delete() {
$path_to_file =  FCPATH . 'application/modules/admin/controllers/module' .'/'. $this->uri->segment(5).'.php';
$path_to_file_lang =  FCPATH . 'application/modules/admin/language'.'/' .'english' .'/'. 'module/'.   $this->uri->segment(5).'lang.php';
$path_to_file_view =  FCPATH . 'application/modules/admin/views/template/module' .'/'. $this->uri->segment(5).'.tpl';

if (unlink(realpath($path_to_file), realpath($path_to_file_lang))  ) {

echo "deleted" .' '. $path_to_file;

echo "<br/>";

echo "deleted" .' '. $path_to_file_lang;

echo "<br/>";

echo "deleted" .' '. $path_to_file_view;

} else {

echo "did not delete";

}
}

I am having trouble with unserialize method does not seem to work for my codeigniter project. What is the best method to unserialize with codeigniter php.

I get a error

A PHP Error was encountered

Severity: Notice

Message: unserialize(): Error at offset 67 of 139 bytes

Filename: extension/model_module.php

Line Number: 25

Model Function

public function getModule($module_id) {
        $query = $this->db->query("SELECT * FROM `" . $this->db->dbprefix . "module` WHERE `module_id` = " . $this->db->escape($module_id) . " ");

        if ($query->row()) {
            return unserialize($query->row('setting'));
        } else {
            return array(); 
        }
    }

I have found the best way to match up url / link with the image. Becaue both url and image are in array I have had to
create two lots of for for($i= 0; $i <; $i++) {} one for the file upload and the other for the link post array.

After created for($i= 0; $i <; $i++) {} for link then I copyied the files['link']['name'][$i] and then set that in
the loop. It all seems to work now.

I can now match up the image with the correct url/link. Did a lot of research and trial and error.

function do_upload() {

$files = $_FILES;
$file_loop = count($_FILES['userfile']['name']);

for($i= 0; $i < $file_loop; $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->file_config());

if (!$this->upload->do_upload()) {

$error = array('error' => $this->upload->display_errors());

$this->load->view('design/banner_form.tpl', $error);

} else {

$data_count = count($_POST['link']);

for ($i=0; $i <$data_count ; $i++) { 

$url = $_POST['link'][$i];

$filename = $files['userfile']['name'][$i];

$this->db->set('link', $url);

$this->db->set('image', $filename);

$this->db->insert('banner_image');

}

$this->load->view('design/banner_list.tpl');

}

} 

}

On my view I am trying to get it so if my input link[] is next to the upload button then that link post will be inserted into the database with image I use codeigniter for a mvc frame work.

I can insert the links and images fine, but the link/url that I type in, in each link input are not matching the uploaded filename. How can I resolve this?

Thanks In Advance

function do_upload() {

        $files = $_FILES;
        $file_loop = count($_FILES['userfile']['name']);

        for($i= 0; $i < $file_loop; $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->file_config());

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

                $this->load->view('design/banner_form.tpl', $error);
            } else {

                $data['link'] = $this->input->post('link');

                if (isset($data['link'])) {
                    foreach ($data['link'] as $link) {
                        $data = array(
                            'link' => $link,
                            'image' => $files['userfile']['name'][$i]
                        );
                    }
                }

                $this->db->insert('banner_image', $data);

                $this->load->view('design/banner_list.tpl', $data);
            }
        } 
    }

View

<?php echo form_open_multipart('admin/design/banners/do_upload');?>

<table>
    <thead>
        <tr>
            <td>Link</td>
            <td>Image</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><input type="text" name="link[]" /></td>
            <td><input type="file" name="userfile[]" size="20" multiple="multiple" /></td>
        </tr>
        <tr>
            <td><input type="link" name="link[]" multiple="multiple" /></td>
            <td><input type="file" name="userfile[]" size="20" multiple="multiple" /></td>
        </tr>
    </tbody>
</table>

<input type="submit" value="upload" />

</form>

The array files for checking if extensions and mime files are not working correct I would like to be able to check file types before move upload. So it will check if file type is allowed

When there should be a error it does not show. I can not seem to get the erorrs to work in the correct order How can I improve my file upload errors to work in correct order?

public function upload() {

        $name = $_FILES['userfile']['name']; 
        $tmp_name = $_FILES['userfile']['tmp_name']; 
        $type = $_FILES['userfile']['type']; 
        $size = $_FILES['userfile']['size']; 
        $error = $_FILES['userfile']['error']; 

        for($i = 0; $i < count($tmp_name); $i++) { 

            $dir = FCPATH . "upload/";

            if (is_dir($dir)) {

                if (!empty($name[$i]) && is_file($name[$i])) {

                        // Allowed file extension types
                    $allowed = array(
                        'jpg',
                        'jpeg',
                        'gif',
                        'png'
                    );

                    if (in_array(utf8_strtolower(utf8_substr(strrchr($name[$i], '.'), 1)), $allowed)) {
                        $this->error['warning'] = 'Incorrect File Type';
                    }

                    // Allowed file mime types
                    $allowed = array(
                        'image/jpeg',
                        'image/pjpeg',
                        'image/png',
                        'image/x-png',
                        'image/gif'
                    );

                    if (in_array($name[$i], $allowed)) {
                        $this->error['warning'] = 'Incorrect File Type';
                    }

                } else {

                    if (move_uploaded_file($tmp_name[$i], $dir . $name[$i])) { 
                        $this->error['warning'] = "move_uploaded_file function failed for ".$name[$i]."<br>"; 
                    }
                }

            } else {
                $this->error['warning'] = 'Directory Not There.';
            }
        } 

        return !$this->error;
    }
}

@Bile Thanks for advice Just a question I have got it working but need to set it so it checks the file size and then file_ext before upload what would you recommend

public function upload() {
        $this->load->library('request');

        $file_path = FCPATH .'upload/';
        $file_name = $this->request->files['file']['name'];
        $file_tmp = $this->request->files['file']['tmp_name'];
        $file_type = $this->request->files['file']['type'];
        $file_size = $this->request->files['file']['size'];
        $file_error = $this->request->files['file']['error'];
        $file_ext = array('png', 'gif', 'ico');
        $file_max_size = 100;

        for ($i= 0; $i < count($file_tmp); $i++) {

            if (move_uploaded_file($file_tmp[$i], $file_path . $file_name[$i])) {

            } else {

                if ($file_name < $file_max_size) {

                    $this->error['waring'] = 'Warning: File'.' '.$file_name[$i].' '.'is more than'.' '.$file_max_size.' '.'KB';

                } else {

                    continue;
                }
            }

        }
    }

When I upload I can upload single files fine but, I cannot seem to upload if input is like

I am not sure on my php upload function how to make it allow multiple files?

Thanks in advance.

public function upload() {
        $this->load->library('request');

        $directory = FCPATH .'upload/';
        $full_path = $directory . basename($this->request->files['file']['name']);
        $file_name = basename($this->request->files['file']['name']);
        $file_ext = array('jpeg', 'jpg', 'gif','png');
        $file_size = 3000;

        if (is_dir($directory)) {

            if (!move_uploaded_file($this->request->files['file']['tmp_name'], $full_path)) {

                if (!in_array(utf8_strtolower(utf8_substr(strrchr($file_name, '.'), 1)), $file_ext)) {
                    $this->error['warning'] = 'Warning: Incorrect file type!';
                }

                if ($_FILES["file"]["size"] < $file_size) {
                    $this->error['warning'] = 'Warning: Incorrect file size!';
                }

                return !$this->error;
            }

        } else {

            $this->error['warning'] = 'Warning: Directory does not exist!';

            return !$this->error;

        }
    }

I would like to know if possible in my php codeigniter modelto be able to insert my file names where it matches up with the link insert post. The link post are in array i.e.

Not sure whats best the name of the file inserts but over does not insert correct name. The input for user file is <input type="file" name="userfile+row_id" the row id produces auto generated number.

Model

public function add_banner_image($banner_id = 0) {
        foreach ($this->input->post('link') as $link) {

        $data = array(
            'banner_id' => $banner_id,
            'link' => $link,
        );

        foreach($_FILES as $field => $file) {
            if (!empty($file)) {

                if ($this->upload->do_upload($field)) {

                    $file_data = $this->upload->data();

                    $data['image'] = $file_data['file_name'];

                }
            }
        }

        $this->db->insert_id();
        $this->db->insert('banner_image', $data);

        }

    }

View

<div class="panel-body">
<?php echo $this->load->view('flashdata/flashdata.tpl');?>
<?php if ($error_warning) { ?>
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<?php echo $error_warning; ?>
</div>
<?php } ?>
<?php echo validation_errors('<div class="alert alert-danger">', '</div>'); ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-banner" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Banner Name</label>
<div class="col-sm-10">
<input type="text" name="name" value="" placeholder="Banner Name" id="input-banner-name" class="form-control" />
<?php if ($error_name) { ?>
<div class="text-danger"><?php echo $error_name; ?></div>
 <?php } ?>
</div>
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="input-status">Banner Status</label>
<div class="col-sm-10">
<select name="status" id="input-status" class="form-control">
<option value="1">Enable</option>
<option value="0">Disabled</option>
</select>
</div>
</div>
<table name="images" class="table table-bordered">
</table>
</form>

</div>
<script>
var row_id = <?php echo $row_id;?>; // Int from controller.

jQuery(document).ready(function() {
  $('button[name="new-title"]').on('click', function(){
    var table = $('table[name="images"]');
    var col_1 = $('<input />', {'name': 'title[]', 'class' ...

I have another script here on same file which allows me to create a new row and each img tag has id="example_and_auto_number" by clicking on a button. That's why I need the readUrl to pick up any id that is in img tag.

<table id="images" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="text-center">Image</td>
</tr>
</thead>
<tbody>
<?php $image_row = 0; ?>
<?php $image_row++; ?>
</tbody>
</table>
</div>
<script type="text/javascript">
var image_row = <?php echo $image_row; ?>;

function addImage() {
html  = '<tr id="image-row' + image_row + '">';
html  += '<td>';
html  += '<img id="example' + image_row + '" class="img-thumbnail" style="width: 100px; height:100px; cursor: pointer;" src="" data-toggle="popover">';
html  += '</td>';
html += '</tr>';    
$('#images tbody').append(html);
image_row++;
}

$(document).ready(function() {
$('body').popover({
    selector: '[data-toggle="popover"]',
    placement: 'right',
    html: 'true',
    content: '<span class="btn btn-primary btn-file"><i class="fa fa-pencil"></i> <input onchange="readURL(this)"  id="file-input" type="file" name="userfile[]"/></span> <button  type="button" id="button-clear" class="btn btn-danger"><i class="fa fa-trash-o"></i></button>'

    });
}); 
</script>
<script type="text/javascript">
        function readURL(input) {
    $('tr').each(function(){
    var img = this;
    if (input.files && input.files[0]) {
    var reader = new FileReader();
    reader.onload = function(e) {
    $(img).attr('src', e.target.result);
    }
    reader.readAsDataURL(input.files[0]);
    }
    });
    }
    $("#file-input").change(function() {
    readURL(this);
    });
</script>

I did that but or some reason the img that is showen over rides first one.

Is this correct?

<script type="text/javascript">
var imgs = document.getElementsByTagName("img");

function readURL(input) {
    for (var i=0;i<imgs.length;i++){
        var id = imgs[i].id;
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
            $(id).attr('src', e.target.result);
            }
            reader.readAsDataURL(input.files[0]);
        }
    }
}

$("#file-input").change(function() {
    readURL(this);
});
</script>

On my readURL() function in my scrtipt. I would like to know what would be the best method in being able to auto get the ID from my img tag. Because I have mulitple img rows that get created with own id.

What would you think so that the reader.onload part can set it so the selector part where put ID can auto get any id from img tag. And work with the attr 'src'. Currently I have to enter each id in manuall which is bit anoying.

Thanks very much in advance.

Script

function readURL(input) {
    if (input.files && input.files[0]) {

        var reader = new FileReader();
        reader.onload = function(e) {
            $('#').attr('src', e.target.result);
        }
            reader.readAsDataURL(input.files[0]);
        }
    }

    $("#file-input").change(function() {
    readURL(this);
});

When I click on my button add new row it creates a new row and with the same content as what is in orignal row.

But for each img I would like to be able to have its own unique id / selector rather than the same id.

How am I able to make that possible with code I have.

<script type="text/javascript">
$("#insert-more").click(function () {
     $("#images").each(function () {
        var tds = '<tr>';

        jQuery.each($('tr:last td', this), function () {
            tds += '<td>' + $(this).html() + '</td>';
        });

        tds += '</tr>';

        if ($('tbody', this).length > 0) {

            $('tbody', this).append(tds);

        } else {

            $(this).append(tds);
        }
    });
});

$(document).ready(function() {
    $('body').popover({
        selector: '#example', //Click on image to active popover Need get to have own unique id.
        placement: 'right',
        html: 'true',
        content : '<span class="btn btn-primary btn-file"><i class="fa fa-pencil"></i> <input onchange="readURL(this)"  id="file-input" type="file" name="userfile[]"/></span>'
    });
}); 
</script>

Also each image/file name has its own link/url I am trying to get it so I can get the file name when both are inserted that the match each other.

When image/file is selected eaither if it is only single or multiple image/file. I am trying to be able to get the name, of it insert into the correct location

I have a custom php function for my multiple upload function. I cannot figure out how to make it so when I insert the file name to the database that it matches the row id, of that insert.

How can I make it so. When I create a new banner that each image multiple images that each match the there inserted id.


Model Function

public function addBanner($data) {
        $this->db->query("INSERT INTO " . $this->db->dbprefix . "banner 
            SET name = " . $this->db->escape($data['name']) . ", 
            status = '" . (int)$data['status'] . "'
        ");

        $banner_id = $this->get_id->get_last_id();

        if (isset($data['banner_image'])) {
            foreach ($data['banner_image'] as $banner_image) {

                // Image File Not Working Need Make It
                // So When New Image It Matches The Banner_Image_ID

                $this->db->query("INSERT INTO " . $this->db->dbprefix . "banner_image 
                    SET banner_id = '" . (int)$banner_id . "', 
                    link = " .  $this->db->escape($banner_image['link']) . ",
                    image = " .  $_FILES['userfile']['name'] . " 
                ");

                $banner_image_id = $this->get_id->get_last_id();

                $this->db->query("INSERT INTO " . $this->db->dbprefix . "banner_image_description 
                    SET banner_image_id = '" . (int)$banner_image_id . "',
                    banner_id = '" . (int)$banner_id . "',
                    title = " .  $this->db->escape($banner_image['title']) . "
                ");
            }
        }
    }

CI Controller Function

public function do_upload_banner() {
        $this->lang->load('admin/design/banners', 'english');

        $valid_formats = array(
            "jpg", 
            "png", 
            "gif", 
            "zip", 
            "bmp",
            'ico'
        );

        $max_file_size = 1024*$this->settings->get('config_file_max_size');

        $path = FCPATH . "upload/"; // Upload directory

        $count = 0;

        if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){

            // Loop $_FILES to exeicute all files

            foreach ($_FILES['userfile']['name'] as $field => $name) {  

                if ($_FILES['userfile']['error'][$field] == 4) {

                    continue; // Skip file if any error ...

I use codeigniter 2+ for my frame work I am having issue with my multple file upload that are in array. I is not picking up the number with in the array.

Example:

name="banner_image[auto_generated_number]['image']"

how to make a foreach work with the banner_image[auto_generated_number]['image']

Currently my code is

    public function do_upload() {
        $config['upload_path'] = './upload/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = '0';
        $config['max_width'] = '*';
        $config['max_height'] = '*';
        $config['overwrite'] = TRUE;

        $this->load->library('upload', $config);
        $this->upload->initialize($config);

        $files = $_FILES['banner_image']['name'];

        foreach ($files as $FIELD => $name) {

        if ($this->upload->do_upload($FIELD)) {

         } else {

            $this->form_validation->set_message('do_upload', $this->upload->display_errors());

            return false;
        }

        }
    }

View sample

<?php $image_row = 0; ?>
<?php foreach ($banner_images as $banner_image) { ?>
<tr>
<td><input type="text" name="banner_image[<?php echo $image_row; ?>][title]" class="form-control" placeholder="Title"></td>
<td><input type="text" name="banner_image[<?php echo $image_row; ?>][link]" class="form-control" placeholder="Link"></td>
<td>
<input type="file" name="banner_image[<?php echo $image_row; ?>][image]" size="20"  multiple="" id="file_<?php echo $image_row; ?>"/>
</td>
</tr>
<?php $image_row++; ?>
<?php } ?>

<script type="text/javascript"><!--
var image_row = <?php echo $image_row; ?>;

function addImage() {
html  = '<tr id="image-row' + image_row + '">';
html += '<td class="text-left">';
html += '<input type="text" name="banner_image[' + image_row + '][title]" value="" placeholder="Title" class="form-control" />';
html += '</td>';
html += '<td class="text-left">';
html += '<input type="text" name="banner_image[' + image_row + '][link]" value="" placeholder="Link" class="form-control" />';
html += '</td>';
html += '<td class="text-left">';
html += '<input type="hidden" name="banner_image[' + image_row + '][image]" id="file_'+ image_row + '"/>';
html += '<input type="file" name="banner_image[' + image_row + '][image]" size="20"  multiple="" id="file_'+ image_row + '"/>';
html += '</td>';
html += '</tr>';

$('#images tbody').append(html);

image_row++;
}