Php 从文件输入中获取名称

Php 从文件输入中获取名称,php,codeigniter,Php,Codeigniter,当我上传我的文件图像时,这个$这个->上传->上传($name)将不起作用 它没有拾取我的字段name=“banner\u image[+image\u row+]['image']” 图像_行生成行id号 Var转储 array(1) { ["banner_image">=> array(5) { ["name">=> array(1) { [1]=> array(1) { ["image">=> string(10) "10-dec.jpg" } }

当我上传我的文件图像时,这个
$这个->上传->上传($name)
将不起作用

它没有拾取我的字段
name=“banner\u image[+image\u row+]['image']”

图像_行生成行id号

Var转储

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) } } } }
在控制器的do\u upload功能上,如何使其拾取正确的字段名?

控制器功能

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;

    }
}
查看

<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>

var image_row=;
函数addImage(){
html='';
html+='';
html+='';

html+='/“>我建议您参考Codeigniter用户指南文件上传类

您已经使用了文本在表单中键入输入。请使用文件键入输入。只需提供一个选项

无论如何,该链接将引导您完成一个简单的文件上传练习

要获取上传文件的文件名,您可以在控制器中使用该文件名。 $filename=$this->upload->data('file_name')

然后,您可以从控制器将其发送到任何模型


希望这能有所帮助。

试试这个,改变这行

name="banner_image[ + image_row + ]['image']"

您错过了
''

还有剧本

html = '<tr id="image-row' + image_row + '">';
html=”;

html+='';

No不起作用。它阻止我添加行。仍然不断地说您没有选择要上载的文件。
html = '<tr id="image-row' + image_row + '">';
html += '<tr id="image-row' + image_row + '">';