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

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

如何解決 Laravel 中保存文件的問(wèn)題?

如何解決 Laravel 中保存文件的問(wèn)題?

PHP
繁花不似錦 2024-01-19 16:56:28
我在數(shù)據(jù)庫(kù)中保存文件時(shí)遇到問(wèn)題,我已經(jīng)完成了編碼,但不知何故,編碼沒有讀取我的 File 函數(shù)的第一行代碼,因?yàn)樗粩嘧x取 else 行,noimage.jpg如果在提交期間未檢測(cè)到文件,則該行將保存。我認(rèn)為問(wèn)題出在我的刀片上。但我想不出來(lái)。選擇文件后,文件名也沒有出現(xiàn)。數(shù)據(jù)也保存到我的數(shù)據(jù)庫(kù)中,但名稱為 noimage.jpg,即使我嘗試提交圖像。public function store(Request $request)    {             $this->validate($request,[            'location' =>'required',            'event_image'=>'image|nullable|max:1999',            'availability'=>'required',        ]);        //handle the file upload        if($request ->hasFile('event_image')){   // to check if user has opted to upload the file                    // get filename with extention            $filenameWithExt = $request->file('event_image')->getClientOriginalName();            //get just filename            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);            //get ext (extention)            $extension =$request->file('event_image')->getClientOriginalExtension();            //filename to store            $fileNameToStore = $filename .'_'.time().'.'.$extension;            //upload image            $path = $request->file('event_image')->storeAs('public/event_images',$fileNameToStore);       }else{           $fileNameToStore ='noimage.jpg'; // if user dont have any file this name will be put on the database       }       $event = new Event;       $event->location = $request->input('event_location');       $event->event_image =$fileNameToStore;       $event->availability =$request->input('event_availability');       $event->admin_id = auth()->user()->id;       $event->save();}
查看完整描述

2 回答

?
阿波羅的戰(zhàn)車

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

我認(rèn)為問(wèn)題在于html input type file本質(zhì),它name attribute缺少:

這:

<input type="file" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="customFile" name="event_image" id="event_image"></label>

應(yīng)該是這樣的:

<input type="file" class="custom-file-input" name="event_image" id="customFile">
                        <label class="custom-file-label" for="customFile"  id="event_image"></label>


查看完整回答
反對(duì) 回復(fù) 2024-01-19
?
牧羊人nacy

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

您必須用于name獲取表單數(shù)據(jù)

它應(yīng)該是

<input type="file" class="custom-file-input" id="customFile" name="event_image ">


查看完整回答
反對(duì) 回復(fù) 2024-01-19
  • 2 回答
  • 0 關(guān)注
  • 203 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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