1
我试图通过上传使用Laravel 5.2形式的视频和图像Laravel 5 - TokenMismatchException在VerifyCsrfToken.php线67
当上传只是它的工作没有任何问题的图像,但是当我尝试上传视频以及它只是抛出了TokenMismatchException在VerifyCsrfToken.php行67错误。
我的表单确实有隐藏的csrf_field {! csrf_field()!}和我的路线是内部路线::组([ '中间件'=> [ '网络'],函数(){}
我只是想不通,为什么这个ISN”牛逼工作
方式:
<form action="{{ url('admin-backend/video') }}" method="POST" enctype="multipart/form-data">
{!! csrf_field() !!}
<input type="text" class="form-control" name="name" placeholder="Name">
<textarea name="description" class="form-control" rows="8"></textarea>
<input type="submit" value="submit">
<input type="file" class="form-control" name="video" />
<input type="file" class="form-control" name="feature_image" />
<input type="file" class="form-control" name="image_1" />
<input type="file" class="form-control" name="image_2" />
<input type="file" class="form-control" name="image_3" />
<input type="file" class="form-control" name="image_4" />
<input type="file" class="form-control" name="image_5" />
<input type="file" class="form-control" name="image_6" />
</form>
路线:
Route::group(['middleware' => ['web']], function() {
Route::get('/admin-backend', function() {
return view('backend.admin.index');
});
Route::get('/admin-backend/video', '[email protected]');
Route::get('/admin-backend/video/create', '[email protected]');
Route::post('/admin-backend/video', '[email protected]');
Route::get('/admin-backend/video/{id}', '[email protected]');
Route::get('/admin-backend/video/{id}/edit', '[email protected]');
Route::put('/admin-backend/video/{id}', '[email protected]');
});
控制器存储()方法:
public function store(Request $request)
{
$fields = Video::prepareVideoUpload($request);
$video = Video::create($fields);
return view('backend.admin.videos.create');
}
视频模式:
protected $table = 'videos';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name','description','feature_image','image_1','image_2','image_3','image_4','image_5','image_6','video','created_at','updated_at'
];
/**
* @param $request
* @return array
*
* This function prepares the video upload by placing all relevant data into the $fields array.
* It creates the necessary folder structure to place the images and video for each shoot
*
*/
public static function prepareVideoUpload($request)
{
$fields = []; //This will be used to store the information in the database instead of request
$fields['name'] = $request['name'];
$fields['description'] = $request['description'];
$videoPath = public_path() . '/videos/' . substr(date("Y/m/d"),0,7); // videoPath looks like - /Applications/MAMP/htdocs/website/public/videos/2016/04
$name = str_replace(' ', '-', $request['name']);
$newVideoPath = $videoPath . '/' . $name;
//if the folder is already created just make the new video name folder
if(is_dir($videoPath)) {
mkdir($newVideoPath);
}else{
//create the folder structure /year/month/video-name
mkdir($newVideoPath, 0777, true);
}
//Create the video and images folders for the individual shoot
mkdir($newVideoPath . '/video');
mkdir($newVideoPath . '/images');
//If the video was uploaded successfully, move it to the images directory
if ($request->hasFile('video') && $request->file('video')->isValid()) {
$request->file('video')->move($newVideoPath . '/video',$request->file('video')->getClientOriginalName());
$fields['video'] = 'videos/' . substr(date("Y/m/d"),0,7) . '/' . $name . '/video/' . $request->file('video')->getClientOriginalName();
}
//If the feature image was uploaded successfully, move it to the images directory
if ($request->hasFile('feature_image') && $request->file('feature_image')->isValid()) {
$request->file('feature_image')->move($newVideoPath . '/images',$request->file('feature_image')->getClientOriginalName());
$fields['feature_image'] = 'videos/' . substr(date("Y/m/d"),0,7) . '/' . $name . '/images/' . $request->file('feature_image')->getClientOriginalName();
}
for($i=1;$i < 7; $i++){
//If the image was uploaded successfully, move it to the images directory
if ($request->hasFile('image_' . $i) && $request->file('image_' . $i)->isValid()) {
$request->file('image_' . $i)->move($newVideoPath . '/images',$request->file('image_' . $i)->getClientOriginalName());
$fields['image_' . $i] = 'videos/' . substr(date("Y/m/d"),0,7) . '/' . $name . '/images/' . $request->file('image_' . $i)->getClientOriginalName();
}
}
return $fields;
}
我没有做任何验证作为然而,这样当我尝试没有视频上传工作并保存到文件夹并将文件夹路径输出到数据库中。但是,当我尝试上传视频时,它会抛出错误。
林有点卡在这里,有没有人有任何想法?
您是否有独特的APP_KEY生成并保存在.env文件中?也请尝试php工匠dump-autoload –
什么是你的config/session.php'driver'值?如果是文件,请确保文件中的“文件”具有正确的路径, –
是在.env文件中生成app_key并转储自动加载dit nothing – user3620531