私はを使用してフォームを介してビデオや画像をアップロードしようとしていますLaravel 5.2Laravel 5 - ちょうど画像をアップロードするとき、私はアップロードしようとするVerifyCsrfToken.phpラインでTokenMismatchException 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 artisan dump-autoloadを試してください –
あなたのconfig/session.php 'driver'値は何ですか?ファイルであれば、同じファイルの 'files'に正しいパスがあることを確認してください。 –
はいapp_keyは.envファイルで生成され、dump autoload ditは何もありません – user3620531