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++;
}
</script>