2011-08-29 21 views
0

您好我想使用下面的codigniter do_upload功能: 但得到這個錯誤:「您沒有選擇要上傳的文件」我做選擇一個文件,當我通過名字我看到名字,但仍然無法上傳...提前感謝幫助。笨文件uplaod

function do_upload() 
{ 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = '100'; 
    $config['max_width'] = '1024'; 
    $config['max_height'] = '768'; 

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

    if (! $this->upload->do_upload()) 
    { 
     $data = array('error' => $this->upload->display_errors()); 
     print_r($data); 
     exit; 
     //$this->load->view('clients_page', $error); 
    } 
    else 
    { 
     $data = array('upload_data' => $this->upload->data()); 
     print_r($data); 
     exit; 
    } 
} 
+0

是你的html文件好嗎? – Efazati

回答

3

我假設你不命名你的<input type="file" />默認userfile。很高興看到您的上傳視圖。

改變這種

$this->upload->do_upload() 

這個

$this->upload->do_upload('audioRef') 
+0

」>

Shak

+0

請參閱更新..... – jondavidjohn

2

I do select a file and when i pass the name i can see the name but still can not upload

這往往是因爲你忽略了設置你的表單提交的multipart/form-data。表單默認爲application/x-www-form-urlencoded,不能包含文件上傳;在這種情況下,您只需獲取文件名即可。

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

順便說一句,

$config['allowed_types'] = 'gif|jpg|png'; 

如果必須使用文件擴展名來檢查文件類型(和它的不妥當,但是這就是笨提供,遺憾的是),還請允許jpeg和任何其他可能的擴展。

$config['upload_path'] = './uploads/'; 

如果上傳文件夾根目錄內(你會被直接投放文件出來吧),這是一個潛在的跨站點腳本漏洞。不幸的是,可以上傳看起來像圖像但實際上包含HTML的文件,包括<script>

以安全的方式做用戶上傳的內容是。參見例如this question的背景。