簡體   English   中英

無需圖像 CodeIgniter 3. 如何?

[英]No image required CodeIgniter 3. How?

我在驗證圖像是否被選中時遇到問題。 我使用 CodeIgniter 3,但我不知道該怎么做。 我有這個代碼:

if ($this->input->post('adminImage') == null){
    $data['image'] = base_url('assets/images/default_avatar.png');
} else {
    $config['upload_path'] = './assets/images/admins';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = 10240;
    $config['max_width'] = 512;
    $config['max_height'] = 512;
    $config['encrypt_name'] = TRUE;

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

    if ($this->upload->do_upload('adminImage')) {
        $uploadData = $this->upload->data();
        $data['image'] = base_url('assets/images/admins/' . $uploadData['file_name']);
    } else {
        $_SESSION['messageDangerSm'] = $this->upload->display_errors();
        redirect(base_url('panel/admins'));
    }
}

如果我不選擇圖像,它會起作用,將先前定義的圖像鏈接發送到數據庫。 但問題是,即使我選擇了一張圖片,它仍然會使用默認圖片發送到數據庫的鏈接,而不是由用戶選擇。 如何修復它,以便在選擇圖像后將圖像鏈接發送到數據庫,如果您不選擇此默認圖像? 預先感謝您的幫助:)

對不起我的英語xD

發送到數據庫的代碼部分在哪里?

 if (!empty($_FILES['file']['name'])) {

    $config['upload_path'] = './assets/images/admins';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = 10240;
    $config['max_width'] = 512;
    $config['max_height'] = 512;
    $config['encrypt_name'] = TRUE;

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

    if ($this->upload->do_upload('file')) {
    $uploadData = $this->upload->data(file_name);

    // now you need to send this to your model and upload to you db
    }
    else {
        $_SESSION['messageDangerSm'] = $this->upload->display_errors();
        redirect(base_url('panel/admins'));
    }

暫無
暫無

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

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