2016-02-05 61 views
0
function do_upload(){//This is my controller// 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['overwrite'] = true; 
    //$config['max_size'] = '100'; 
    //$config['max_width'] = '1024'; 
    //$config['max_height'] = '768'; 
    $this->load->library('upload'); 
    $this->upload->initialize($config); 
    $this->upload->do_upload(); 
    if (!$this->upload->do_upload()){//I also found out that this is the part that is not working 
     echo "failed!"; 
    } 
    else{ 
     $this->upload->data(); 
     echo "success!"; 
    } 
} 

「我已經嘗試了一些教程,使這項工作,但似乎沒有爲這個工作」

+0

檢查你的表單enctype屬性是否設置。 http://www.w3schools.com/tags/att_form_enctype.asp – Sundar

+0

<?php echo form_open_multipart((base_url())。'admin/do_upload');?>

<?php echo form_close(); ?> 我已經檢查過,這裏是我的表格 – John

+0

的代碼,你有沒有失敗的消息,然後試試這個print_r($ this-> upload-> display_errors());您也可以將文件上傳字段名稱作爲do_upoad('userfile')方法中的參數傳遞。示例userfile是表單字段名稱 – Sundar

回答

0

這可能是文件權限問題「上傳」目錄。設置適當的可寫入權限來上傳文件夾。

0
'upload_path' => $image_path, 
'allowed_types' => "gif|jpg|png|jpeg", 
'overwrite' => TRUE, 
'max_size' => "2048000", 
'max_height' => "1000", 
'max_width' => "2000" 

試試這個。

+0

請提供更多信息,說明;) – Soren