LoginSignup
2
6

More than 5 years have passed since last update.

【メモ】Laravelで画像アップロードしようとしたらフォームの記述が足りなくてアップ出来なかったのでメモ

Last updated at Posted at 2017-07-26

普通に以下のようにフォーム記述したが、
何故かファイル名しか送信出来ていなかった。
(送信先で$_FILESでvar_dumpするとemptyになった)

<form class="form-group" method="post" action="{{ url('/users/'.$user->id) }}">
   {{ csrf_field() }}                
   {{ method_field('PATCH') }}                     
   <input type="file" name="img_path">
   <input type="submit" value="変更">
</form>

フォームを以下のように変更するとうまく行った。

<form class="form-group" method="post" action="{{ url('/users/'.$user->id) }}" enctype="multipart/form-data" files='true'>
   {{ csrf_field() }}                
   {{ method_field('PATCH') }}                     
   <input type="file" name="img_path">
   <input type="submit" value="変更">
</form>

【参考】
http://laraweb.net/tutorial/1283/

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6