2016-04-06 68 views
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; 

} 

我沒有做任何驗證作爲然而,這樣當我嘗試沒有視頻上傳工作並保存到文件夾並將文件夾路徑輸出到數據庫中。但是,當我嘗試上傳視頻時,它會拋出錯誤。

林有點卡在這裏,有沒有人有任何想法?

+0

您是否有獨特的APP_KEY生成並保存在.env文件中?也請嘗試php工匠dump-autoload –

+0

什麼是你的config/session.php'driver'值?如果是文件,請確保文件中的「文件」具有正確的路徑, –

+0

是在.env文件中生成app_key並轉儲自動加載dit nothing – user3620531

回答

2

我的猜測是你對POST數據的最大大小限制,這導致它只是放棄輸入。

你可以調整你的網絡服務器和PHP到一個更高的限制,看看它是否有幫助。

post_max_size在php.ini將是一個很好的開始。

相關問題