2015-04-30 201 views
1

我嘗試用代碼點火器上傳文件,但我得到錯誤您沒有選擇一個文件上傳..任何人都知道如何解決這個問題?我的var_dump表明這一點:文件上傳錯誤codeigniter

array(14) { 
    ["file_name"]=> string(0) "" 
    ["file_type"]=> string(0) "" 
    ["file_path"]=> string(25) "./assets/profilepictures/" 
    ["full_path"]=> string(25) "./assets/profilepictures/" 
    ["raw_name"]=> string(0) "" 
    ["orig_name"]=> string(0) "" 
    ["client_name"]=> string(0) "" 
    ["file_ext"]=> string(0) "" 
    ["file_size"]=> NULL 
    ["is_image"]=> bool(false) 
    ["image_width"]=> NULL 
    ["image_height"]=> NULL 
    ["image_type"]=> string(0) "" 
    ["image_size_str"]=> string(0) "" 
} 

我控制器

if ($this->input->server('REQUEST_METHOD') == 'POST') { 
    $id = $this->input->post('id_gids'); 

    $config['upload_path'] = './assets/profilepictures/'; 
    $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
    $config['max_size'] = '100000000'; 
    $config['overwrite'] = TRUE; 
    $config['remove_spaces'] = TRUE; 
    $config['encrypt_name'] = FALSE; 

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

    $image_path = $this->upload->data(); 
    $gidsimg = $image_path["file_name"]; 

    var_dump($image_path); 
    var_dump($this->upload->display_errors()); 

    $data = array(
    'gids_name' => $this->input->post('voornaam'), 
    'gids_surname' => $this->input->post('name'), 
    'gids_city' => $this->input->post('stad'), 
    'gids_email' => $this->input->post('mail'), 
    'gids_password' => $this->input->post('password'), 
    'gids_bio' => $this->input->post('bio'), 
    'gids_year' => $this->input->post('jaar'), 
    'gids_interest' => $this->input->post('studie'), 
    'gids_picture' => "assets/profilepictures/".$gidsimg 
    ); 

    $this->Mod_model->update($id, $data); 
} 

我看來

<form action="" method="post" enctype="multipart/form-data"> 
    <input type="hidden" name="id_gids" value="<?php echo $w['gids_id'] ?>"/> 
    <div class="pictureprofile"> 
    <img src="../../<?php echo $w['gids_picture'] ?>" alt="Profile Picture" class="profilepicture"> 
    </div><br> 
    <input type="file" name="gids_img"/><br/> 
</form> 

回答

0

行:

$this->upload->do_upload('file'); 

爲do_upload功能參數期待名稱的文件上傳fi場,所以你應該將其更改爲:

$this->upload->do_upload('gids_img'); 
+0

我試過,但我得到了同樣的錯誤 – user3071261

+0

檢查你的PHP的max_upload_size值。 ini文件。這可能是因爲您嘗試上傳的圖片大於最大允許尺寸 – gabe3886

1

首先你正在使用笨,你的形式action is empty。不知道你的數據是如何達到控制器

<form action="" method="post" enctype="multipart/form-data"> 

變化表單標籤codignitor standers並嘗試

echo form_open_multipart('controller/function');