为什么我的图片上传不起作用


why my image upload doesnt work?

我知道我的问题并不新鲜,但我不知道为什么它不起作用。

在我的控制器中,如果是false并且我图像不上传,图像的数据不保存在数据库中,否则执行。

<form name="f" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>index.php/aparteman/save" role="form">
<!--<input type="text" name="gh" id="gh"></input>-->
<input type="hidden" name="g" id="g" value=<?php echo $insert_id; ?>></input>
<div class="col-md-1"></div>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-primary" onclick="$(this).parent().find('input[type=file]').click();">
<span class="glyphicon-class glyphicon glyphicon-folder-open"></span>&nbsp;Browse</span>
<input onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[''|/]/).pop());" style="display: none; width:50%;" type="file" name="Name1" id="Name1"></input>
</span>
</form>

微控制器

public function save()
{               
    $config['upload_path']='/upload/';
    $config['allowed_types']= 'gif|jpg|png|jpeg';
    $config['max_size']= 2000;
    $config['max_width']= 1024;
    $config['max_height']= 768;
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    if ($this->upload->do_upload('Name1'))
    {
        $data = array('upload_data' => $this->upload->data());
        $my_data['photo']=$data['upload_data']['file_name'];
        $my_data = array(
        'FIDKhane' => $this->input->post('g')
                    );
        $this->load->model('apartemanmodel');
        $this->apartemanmodel->insert_images($my_data);
    }           
    else {
        echo "...";            
    }

我的型号

  function insert_images($my_data)
  { 
    $this->db->set('Name1',$my_data['photo']);
    $this->db->set('FIDKhane',$my_data['FIDKhane']);
    $this->db->insert('imagekhane');    
 } 

谢谢你的帮助。

看起来您已经覆盖了变量$my_data。请尝试使用以下代码:

$my_data = array(
  'photo' => $data['upload_data']['file_name'],
  'FIDKhane' => $this->input->post('g')
);
相关文章: