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

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

我想在 Laravel 上發布圖片

我想在 Laravel 上發布圖片

PHP
千萬里不及你 2022-05-27 16:26:55
所以我創建了一個可以像這樣發布圖像的表單,并在我檢查視圖時嘗試處理圖像<form  action="{{ $action }}" enctype="multipart/form-data" method="post"> <input type="file" name="imagefile" accept="image/*"> <input type="text" name="content"> <button tyoe="submit">OK</button></form>用控制器處理取出圖像并保存位置,同時觀看其他人的博客$post_data = $request->except('imagefile');$imagefile = $request->file('imagefile');$temp_path = $imagefile->store('public/temp');$a = new Test;$a->fill($request->all())->save();我以為一切順利,但出現了錯誤無法將值 NULL 插入“圖像文件”之后我檢查了但原因不明白。
查看完整描述

3 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

試試這個它可以幫助你..


$post_data = $request->except('imagefile');

$imagefile = $request->file('imagefile');

$temp_path = $imagefile->store('public/temp');

$filename = $request->file('image');

$post_data->imagefile = $filename;


$a = new Test;

$a->fill($post_data)->save();

或者


$a = new Test;

$a->imagefile = $filename; // here imagefile equal to your db fild

$a->save();


查看完整回答
反對 回復 2022-05-27
?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

您需要在保存之前將文件名分配給值數組。也不要使用$request->all();這個包含圖像對象&我們在保存時不需要它。我們只需要文件名。在下面的代碼中,我在保存之前將文件名分配到 $post_data 數組中。


$post_data = $request->except('imagefile');

$imagefile = $request->file('imagefile');

$temp_path = $imagefile->store('public/temp');


$filename = $request->file('image')->hashName();

$post_data->imagefile = $filename;


$a = new Test;

$a->fill($post_data)->save();


查看完整回答
反對 回復 2022-05-27
?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

請嘗試以下行以獲取有關您的圖像的所有參數。

$圖像文件 = $_FILES;

在繼續之前打印 $imagafile 數組。


查看完整回答
反對 回復 2022-05-27
  • 3 回答
  • 0 關注
  • 113 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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