mardi 24 juillet 2018

File upload in Laravel via ajax

Problem i am facing is that when i submit the form i get null on server side. i have tried many ways which i got from internet but they didn't work for me. tell me what is my error Here is my Ajax Code

     $(document).ready(function(){
         $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf- 
             token"]').attr('content')
        }
    });

   $("#user-form").on('submit', function(e){
    e.preventDefault();

    var formData = new FormData($(this)[0]);

    $.ajax({
        url: 'adduser',
        type: 'POST',
        data: formData,
        success: function (data) {

        },
        cache: false,
        processData: false
    });
  });
});

PHP CODE

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

            $name = 'Hello.'.$request->file('image')- 
             >getClientOriginalExtension();

            $image['filePath'] = $name;
            $request->file('file')->move('D:\BidImages', $name);



            response()->json('Success');

my html form

    <form id="user-form" class="form-horizontal" enctype="multipart/form-data">

            {!! csrf_field() !!}


  <input type="file" class="custom-file-input"id="image" name="image">
                    <label class="custom-file-label" 

  <input  type="submit" class="btn btn-primary" id="add-user" 
  value="Add User">

  </form>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire