亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用codeigniter在MYSQL數據庫中使用數組索引上傳文件

如何使用codeigniter在MYSQL數據庫中使用數組索引上傳文件

PHP
慕森王 2021-11-26 16:00:39
對不起,如果這是一個菜鳥問題,我仍然是 codeigniter 的新手,這是我的問題,我有一個回復,看起來像這樣Array([0] => Array([original_name] => avatar_img12.png [filename] => avatar_img12.png) [1] => Array([original_name]=> add_icon27.png [filename] => add_icon27.png))我有 2 個輸入類型的文本框文件,這就是為什么它只有 0 和 1 的索引,在需要兩個輸入類型文件的幫助下,我能夠將它上傳到我的數據庫中,但我的問題是用戶何時更新他們的數據,他們可能會更新相同的文件,或者只是其中的一個。我怎樣才能只更新特定的索引。我已經嘗試為每個索引創建一個 if 語句,但我有一個錯誤offset 1或offset 0這是我的模型          if($files[0] != '' && $files[1]==''){            $this->db->select('id,picture_id');            $this->db->from($this->project_tbl);            $this->db->where('id',$id);             $query = $this->db->get();                if($query->num_rows() > 0){                    $this->db->where('id', $query->row()->picture_id);                    $this->db->update($this->project_core_documents, $files[0]);                }            }else if($files[1] != '' && $files[0]==''){                $this->db->select('id,detailed_report_id');                $this->db->from($this->project_tbl);                $this->db->where('id',$id);                $query = $this->db->get();                    if($query->num_rows() > 0){                        $this->db->where('id', $query->row()->detailed_report_id);                        $this->db->update($this->project_core_documents, $files[1]);                    }            }else{                //both files            }這是我的表格<form class="kt-form" id = "save_project" enctype="multipart/form-data"><input type="file" class="form-control project_userfiles" name = "userfile[]" multiple=""><input type="file" class="form-control project_userfiles" name = "userfile[]" multiple=""></form>這就是我如何獲取用于上傳的數組 $files 我正在使用幫助程序。這樣我就可以在我的控制器上調用它。我有一個錯誤,undefined offset:1如果我只是為索引 [0]undefined offset:0上傳,如果我只是為索引 [1] 上傳,如果兩個索引都有一個值,則沒有錯誤,我仍然不知道如何在我的查詢中執行它,如果這兩個索引都有一個值。提前致謝。對不起,如果我的解釋不那么準確。
查看完整描述

1 回答

?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

它得到未定義的索引,因為在您的上傳功能上,如果您只上傳單個文件,那么它只會生成單個上傳數據,因此 the $files[0]or$files[1]數組將是未定義的,并且松散相等或松散非相等條件將失敗。

為了讓你的邏輯工作,你可以使用empty檢查:


if (!empty($files[0]) && empty($files[1])) {

    $this->db->select('id,picture_id');

    $this->db->from($this->project_tbl);

    $this->db->where('id', $id);

    $query = $this->db->get();

    if ($query->num_rows() > 0) {

        $this->db->where('id', $query->row()->picture_id);

        $this->db->update($this->project_core_documents, $files[0]);

    }

} else if (!empty($files[1]) && empty($files[0])) {

    $this->db->select('id,detailed_report_id');

    $this->db->from($this->project_tbl);

    $this->db->where('id', $id);

    $query = $this->db->get();

    if ($query->num_rows() > 0) {

        $this->db->where('id', $query->row()->detailed_report_id);

        $this->db->update($this->project_core_documents, $files[1]);

    }

} else {

    //both files

}

if即使其中一個$files具有未定義的索引,這也會執行該塊。但是你應該注意,else如果兩者$files都不為空,并且兩者都$files為空,則該語句將被執行


查看完整回答
反對 回復 2021-11-26
  • 1 回答
  • 0 關注
  • 150 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號