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

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

我正在嘗試使用“干預(yù)\圖像庫”保存圖像。我發(fā)現(xiàn)一個錯誤圖像源不可讀

我正在嘗試使用“干預(yù)\圖像庫”保存圖像。我發(fā)現(xiàn)一個錯誤圖像源不可讀

PHP
慕哥6287543 2024-01-19 20:47:49
 public function store(Request $request)    {              $this->validate($request, [            'judul'       => 'required',            'category_id' => 'required',            'konten'     => 'required',            'gambar'      => 'required',        ]);        $gambar = $request->gambar;        $new_gambar = time().$gambar->getClientOriginalName();                $post = Posts::create([            'judul'       => $request->judul,            'category_id' => $request->category_id,            'konten'      => $request->konten,            'gambar'      =>  'public/uploads/posts/'.$new_gambar,            'slug'        => Str::slug($request->judul),            'users_id'    => Auth::id()        ]);        $img = Image::make('public/uploads/',$gambar->getRealPath())->resize(300,300)->保存('public/uploads/', $gambar->getClientOriginalName()); $gambar->move('上傳', $new_gambar); $post->tags()->attach($request->tags);        return redirect('post');    }
查看完整描述

2 回答

?
慕仙森

TA貢獻1827條經(jīng)驗 獲得超8個贊

在 html 表單中添加 enctype

enctype="multipart/form-data"

并在您的控制器中對此進行更改:

$img = Image::make($request->file('gambar')->getRealPath());

另請檢查上傳文件的目錄的權(quán)限


查看完整回答
反對 回復(fù) 2024-01-19
?
繁星點點滴滴

TA貢獻1803條經(jīng)驗 獲得超3個贊

確保表單具有 enctype:


<form class="form" ... enctype="multipart/form-data">

變更控制器


use Intervention\Image\ImageManagerStatic as Image;


public function store(Request $request)

{

  $this->validate($request, [

    // 'judul'       => 'required',

    //if judul column type is varchar need to set max varchar value or less

    //varchar max 255, if higer than 255 strings, extra string will be truncated

    'judul'       => 'required|string|max:200', 

    // 'category_id' => 'required',

    //category should exist

    'category_id' => 'required|exists:categories,id',

    'konten'      => 'required',

    // 'gambar'      => 'required',

    //validating image is successfully uploaded and is image format

    'gambar'      => 'required|file|image|mimes:jpg,jpeg,png',

    //validation for tags, assuming 1 input <select name="tags[]" multiple="multiple"/>

    'tags'        => 'array',

    'tags.*'        => 'exists:tags,id'//each value of input select exists in tags table

  ]);


  // $gambar = $request->gambar; 

  //get the file from <input type="file" name="gambar"/>

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

  $new_gambar = time().$gambar->getClientOriginalName();

  //make path to save image: sample public path

  $file_path = public_path("uploads/post/{$new_gambar}"); 


  $img = Image::make($gambar)

  ->resize(300,300)

  ->save($file_path);


  $post = Posts::create([

    'judul'       => $request->judul,

    'category_id' => $request->category_id,

    'konten'      => $request->konten,

    // 'gambar'      =>  'public/uploads/posts/'.$new_gambar,

    //should maake the image first

    'gambar'      => $file_path,

    'slug'        => Str::slug($request->judul),

    'users_id'    => Auth::id() // <- if it is to get current logged in user, use  Auth::user()->id

  ]);


  // $gambar->move('uploads', $new_gambar); //let Intervention do this for you

  // $post->tags()->attach($request->tags); 

  //if tags exists (get values frominput select)

  $post->tags()->sync($request->input('tags', []));

  //$request->input('tags', []) <- if input tags is not null get value, else use empty array

  //if route have name e.g Route::get('post', 'PostController@post')->name('post');

  //return redirect()->route('post');

  return redirect('post');

}


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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