第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用codeigniter在MYSQL數(shù)據(jù)庫(kù)中使用數(shù)組索引上傳文件

如何使用codeigniter在MYSQL數(shù)據(jù)庫(kù)中使用數(shù)組索引上傳文件

PHP
慕森王 2021-11-26 16:00:39
對(duì)不起,如果這是一個(gè)菜鳥(niǎo)問(wèn)題,我仍然是 codeigniter 的新手,這是我的問(wèn)題,我有一個(gè)回復(fù),看起來(lái)像這樣Array([0] => Array([original_name] => avatar_img12.png [filename] => avatar_img12.png) [1] => Array([original_name]=> add_icon27.png [filename] => add_icon27.png))我有 2 個(gè)輸入類(lèi)型的文本框文件,這就是為什么它只有 0 和 1 的索引,在需要兩個(gè)輸入類(lèi)型文件的幫助下,我能夠?qū)⑺蟼鞯轿业臄?shù)據(jù)庫(kù)中,但我的問(wèn)題是用戶(hù)何時(shí)更新他們的數(shù)據(jù),他們可能會(huì)更新相同的文件,或者只是其中的一個(gè)。我怎樣才能只更新特定的索引。我已經(jīng)嘗試為每個(gè)索引創(chuàng)建一個(gè) if 語(yǔ)句,但我有一個(gè)錯(cuò)誤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>這就是我如何獲取用于上傳的數(shù)組 $files 我正在使用幫助程序。這樣我就可以在我的控制器上調(diào)用它。我有一個(gè)錯(cuò)誤,undefined offset:1如果我只是為索引 [0]undefined offset:0上傳,如果我只是為索引 [1] 上傳,如果兩個(gè)索引都有一個(gè)值,則沒(méi)有錯(cuò)誤,我仍然不知道如何在我的查詢(xún)中執(zhí)行它,如果這兩個(gè)索引都有一個(gè)值。提前致謝。對(duì)不起,如果我的解釋不那么準(zhǔn)確。
查看完整描述

1 回答

?
慕虎7371278

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊

它得到未定義的索引,因?yàn)樵谀纳蟼鞴δ苌?,如果您只上傳單個(gè)文件,那么它只會(huì)生成單個(gè)上傳數(shù)據(jù),因此 the $files[0]or$files[1]數(shù)組將是未定義的,并且松散相等或松散非相等條件將失敗。

為了讓你的邏輯工作,你可以使用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即使其中一個(gè)$files具有未定義的索引,這也會(huì)執(zhí)行該塊。但是你應(yīng)該注意,else如果兩者$files都不為空,并且兩者都$files為空,則該語(yǔ)句將被執(zhí)行


查看完整回答
反對(duì) 回復(fù) 2021-11-26
  • 1 回答
  • 0 關(guān)注
  • 144 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)