Php laravel中的Ajax 419状态错误

Php laravel中的Ajax 419状态错误,php,jquery,ajax,laravel,laravel-5,Php,Jquery,Ajax,Laravel,Laravel 5,我尝试使用AJax、Jquery和Laravel上传图像。在这里,我尝试了这么多的解决方案,但仍然得到419个错误,在某些情况下得到500个内部错误 我试过的代码是 <form method="POST" id="needs" novalidate enctype="multipart/form-data"> {{csrf_field()}} <input name="image1" id="image1" type="f

我尝试使用AJax、Jquery和Laravel上传图像。在这里,我尝试了这么多的解决方案,但仍然得到419个错误,在某些情况下得到500个内部错误

我试过的代码是

<form method="POST" id="needs" novalidate enctype="multipart/form-data">
            {{csrf_field()}}
                <input name="image1" id="image1" type="file" class="form-control" required="" />
                <br>
                <input type="file" name="image2" id="image2" class="form-control" required/>
                <br>
                <input type="file" name="image3" id="image3" class="form-control" required/>
                <br>
                <input type="file" name="image4" id="image4" class="form-control" required/>
                <br>
                <input type="file" name="image5" id="image5" class="form-control" required />
                <br>
                <button type="button" id="upload_image" name="upload_image" class="btn btn-lg btn-success" onclick="image_up();">Upload</button>
              </form>
路线:

Route::post('/', 'CollagePrimController@post')->name('collage.store');

请任何人帮助我解决这个问题。提前感谢

如果文件夹已创建,请添加文件夹权限。
否则创建文件夹并向该文件夹添加777或755权限。

Laravel 419状态错误仅与令牌授权相关

在您的标题部分添加以下代码:

<meta name="csrf-token" content="{{ csrf_token() }}">
如果仍然出现419错误,则通过修改app/Http/Middleware/VerifyCsrfToken.php从特定路由禁用CSRF令牌

class VerifyCsrfToken extends BaseVerifier
{

 // The URIs that should be excluded from CSRF verification.

    protected $except = [
    "/*"
    ];
}

我在当地跑步。并且它仅在windows中请检查我的更新问题。在这里,我为控制器添加了代码。您没有将文件tmp文件保存到您的目录中。尝试以下代码$image=$request->file('image1')$filename=str_random(12)。“.$image->getClientOriginalExtension()$图像->移动(公共路径('collage/'),$filename)$拼贴1=Image::make(公共路径('collage/')。$filename)$拼贴1->保存(公共路径('拼贴/')。$filename);事实上,formdata没有通过。我建议首先尝试使用传统的post上传图像,一旦你知道它可以工作,那么你可以使用ajax将其复杂化。是的@amarnasan。我试过用传统的贴子,非常好。那么,只有我试过使用ajax,你能帮我吗?那么,我会(使用firebug或在使用浏览器时按F12键时得到的任何东西)比较使用常规和ajax时实际发送的查询、参数和标题,检查差异,使后者看起来像前者
$.ajaxSetup({
  headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});
class VerifyCsrfToken extends BaseVerifier
{

 // The URIs that should be excluded from CSRF verification.

    protected $except = [
    "/*"
    ];
}