簡體   English   中英

Codeigniter不顯示文件上傳錯誤

[英]codeigniter not showing file upload error

我正在使用CodeIgniter文件上傳類上傳圖像。 但是,如果我嘗試選擇pdf而不是圖像,則在提交表單時不會出現任何錯誤。

相關代碼

$config = array(
    'allowed_types' => 'jpg|jpeg|gif|png',
    'upload_path'   => $this->article_path.'/magazine',
    'max_size'      => 2000
);

$this->load->library('upload', $config);
$this->upload->do_upload();
$this->upload->display_errors();
$image_data = $this->upload->data();

這是因為您從未瀏覽過文檔( 此處 ),請這樣做是為了在CodeIgniter框架中表現更好。


這應該使您警惕(請閱讀評論)

$config = array(
    'allowed_types' => 'jpg|jpeg|gif|png',
    'upload_path'   => $this->article_path.'/magazine',
    'max_size'      => 2000
);

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

if ( ! $this->upload->do_upload()) //important!
{
    // something went really wrong show error page
    $error = array('error' => $this->upload->display_errors()); //associate view variable $error with upload errors

    $this->load->view('upload_form', $error); //show error page
}
else
{
    //all is good we upload
    $data = array('upload_data' => $this->upload->data()); 

    $this->load->view('upload_success', $data);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM