dongshanxiao7328 2015-01-02 14:05
浏览 17

从文件输入中获取名称

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>
  • 写回答

2条回答 默认 最新

  • dongqian2021 2015-01-03 05:09
    关注

    I suggest you to refer the Codeigniter Userguide File upload class. https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

    You have used text type input in the form. Use file type input. Just giving an option.

    Anyways the link will walk you through a simple file uploading exercise.

    To get the file name of the uploaded file you can use this in the controller. $filename = $this->upload->data('file_name');

    Then from controller you can send it to any model.

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料