Laravel 5 Ajax File/Image Upload

前端 未结 3 1177
挽巷
挽巷 2020-12-14 18:01

I have an issue in my laravel ajax application,

I cant upload images/files through ajax POST.

here is my code.

Ajax..

/*Add new catag         


        
相关标签:
3条回答
  • 2020-12-14 18:35

    Two things to change:

    Change your js file from:

     data:{
        logo:new FormData($("#upload_form")[0]),
     },
    

    To:

     data:new FormData($("#upload_form")[0]),
    

    Because you would like to send the whole form.

    In your html:

    Add a name to your file input field

    <input type="file" class="form-control" id="catagry_logo">
    

    To:

    <input type="file" name="logo" class="form-control" id="catagry_logo">
    
    0 讨论(0)
  • 2020-12-14 18:36

    it doesn't work for me because of dataType:'json'. If anyone gets error just remove dataType:'json'.

    0 讨论(0)
  • 2020-12-14 18:41

    Check in your controller what you get when you post:

    echo dd(Input::all()); 
    

    Check files object in php. This in PHP:

    $_FILES
    
    Request::file("logo");
    

    Yeah, you're not really posting any data? Is the form really posting?

    0 讨论(0)
提交回复
热议问题