When I upload my file image this !$this->upload->do_upload($name)
will not work.
It is not picking up my field name="banner_image[ + image_row + ]['image']"
The image_row generates the row id number.
Var dump
array(1) { ["banner_image">=> array(5) { ["name">=> array(1) { [1]=> array(1) { ["image">=> string(10) "10-dec.jpg" } } ["type">=> array(1) { [1]=> array(1) { ["image">=> string(10) "image/jpeg" } } ["tmp_name">=> array(1) { [1]=> array(1) { ["image">=> string(24) "C:\Xampp\tmp\phpC1F6.tmp" } } ["error">=> array(1) { [1]=> array(1) { ["image">=> int(0) } } ["size">=> array(1) { [1]=> array(1) { ["image">=> int(261032) } } } }
On the controller do_upload function how can I make it pick up field name correct?
Controller function
function do_upload() {
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '3000';
$config['max_width'] = '*';
$config['max_height'] = '*';
$this->load->library('upload', $config);
$this->upload->initialize($config);
// this below is same as whats on set_rules
$name = "banner_image[' + image_row + '][image]"; // + image_Row + is id as shown on view
if (!$this->upload->do_upload($name)) {
$this->form_validation->set_message('do_upload', $this->upload->display_errors());
return false;
} else {
return true;
}
}
View
<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">';
<?php foreach ($languages as $language) { ?>
html += '<div class="input-group" style="margin-bottom: 20px;">';
html += '<span class="input-group-addon"><img src="<?php echo base_url("image/flags");?>/<?php echo $language["image"]; ?>"></span><input type="text" name="banner_image[' + image_row + '][banner_image_description][<?php echo $language["language_id"]; ?>][title]" value="" placeholder="Name Of Banner" class="form-control" />';
html += '</div>';
<?php } ?>
html += '</td>';
html += '<td class="text-left">';
html += '<input type="text" name="banner_image[' + image_row + '][link]" value="" placeholder="Website Page Url" class="form-control" />';
html += '</td>';
html += '<td class="text-left">';
html += '<div class="imagePreview" class="img-thumbnail"></div>';
html += '<input id="idFile" type="file" name="banner_image[' + image_row + '][image]" onchange="previewImage(this,[256],4);" />';
html += '</td>';
html += '<td class="text-left">';
html += '<input type="text" name="banner_image[' + image_row + '][sort_order]" value="" placeholder="Sort Order" class="form-control">';
html += '</td>';
html += '<td class="text-left">';
html += '<button type="button" onclick="$(\'#image-row' + image_row + '\').remove();" data-toggle="tooltip" title="Remove" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button>';
html += '</td>';
html += '</tr>';
$('#images tbody').append(html);
image_row++;
}
</script>