vendredi 12 novembre 2021

How can I upload image in local folder laravel?

I am new in larval development, I am unable to upload image in local folder and I am getting error getClientOriginalExtension() on null. Even I have added code enctype="multipart/form-data" in my form, but still am getting the error. Can anyone give suggestion how to resolve this issue. I have given below my code. MyBlade file

        ****MyBlade file****

                   <form action="" method="POST" enctype="multipart/form-data" accept-charset="utf-8"  >
                      @csrf
                     
                      <div class="form-group row">
                          <label for="uname" class="col-md-4 col-form-label text-md-right">User Name</label>
                          <div class="col-md-6">
                              <input type="text" id="username" class="form-control" name="username" required />
                              @if ($errors->has('username'))
                                  <span class="text-danger"></span>
                              @endif
                          </div>
                      </div>
                       <div class="form-group row">
                        <label for="name" class="col-md-4 col-form-label text-md-right">Profile Picture</label>
                        <div class="col-md-6">
                        <input id="image" type="file" class="form-control" name="image">
                    </div>
                 </div>

My Controller File

       if ($request->input('image')!=null){
        $files = $request->input('image');

        $extension = $files->getClientOriginalExtension();
        $filaname = time().','.$extension;
        $files->move('public/image/',$filaname);
       // $post->image= $filaname;
     }
       else{
         return $request;
       }
        




          

I am getting err:Call to a member function getClientOriginalExtension() on bool



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire