2016-07-29 61 views
0

我試圖實現CodeIgniter的upload庫。但每次我嘗試上傳時,都會一直說我沒有選擇要上傳的文件。CodeIgniter上傳圖片沒有輸入

下面是代碼:

查看:

<form action="<?= base_url().'principal/updateuniform' ?>" method="post"> 
        <h3 style="text-align:center">Polo</h3> 
        <input type="hidden" name="imageid" value="<?= $img_id ?>"> 
        <input type="hidden" name="imagename" value="<?= $img_name ?>"> 
        <input type="file" name="imagefile" accept="image/*" /><br> 
        <button type="submit" class="btn btn-gold"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Upload</button> 
       </form> 

上傳功能:

function updateuniform(){ 
     $img_id = $this->input->post('imageid'); 
     $img_name = $this->input->post('imagename'); 

     $config['upload_path']   = './images/'; 
     $config['allowed_types']  = 'gif|jpg|png'; 
     $config['max_size']    = 5000; 
     $config['max_width']   = 3000; 
     $config['max_height']   = 4000; 
     $config['overwrite']   = TRUE; 
     $config['file_name']   = $img_name; 

     $this->load->library('upload', $config); 
     $this->upload->initialize($config); 

     $img = $this->input->post('imagefile');; 

     $id = $this->session->userdata('id'); 
     $user['user'] = $this->UsersModel->select_principal($id); 

     if (!$this->upload->do_upload($img)){ 
      $data['error'] = $this->upload->display_errors(); 
      $data['uniforms'] = $this->InfoModel->getUniforms(); 

      $this->load->view('include/header_principal',$user); 
      $this->load->view('principal/manage_uniforms', $data); 
      $this->load->view('include/footer_principal'); 
     } else { 
      $img_path = 'images/'.$this->upload->data('orig_name'); 
      $data['success'] = 'Uniforms has been updated.'; 

      $this->InfoModel->updateUniform($img_path); 

      $this->load->view('include/header_principal',$user); 
      $this->load->view('principal/manage_uniforms', $data); 
      $this->load->view('include/footer_principal'); 
     } 

    } 

我也試圖echo$img和它顯示的文件名。

回答

1
$this->upload->do_upload($img) 

帕拉姆應該是filedname,如:

$this->upload->do_upload('imagefile') 
0

添加ENCTYPE = 「的multipart/form-data的」 在視你的表單標籤這可以讓你獲得$ _FILE值,這將解決你的問題我猜