Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5-VerifyCsrfToken.php第67行中的令牌不匹配异常_Php_Laravel_Laravel 5.2 - Fatal编程技术网

Laravel 5-VerifyCsrfToken.php第67行中的令牌不匹配异常

Laravel 5-VerifyCsrfToken.php第67行中的令牌不匹配异常,php,laravel,laravel-5.2,Php,Laravel,Laravel 5.2,我正在尝试使用Laravel 5.2通过表单上传视频和图像 当只上传图像时,它不会出现任何问题,但是当我尝试上传视频时,它只会在VerifyCsrfToken.php第67行中抛出标记不匹配异常 我的表单确实有隐藏的csrf_字段{!!csrf_字段()!!}并且我的路由在路由::组(['middleware'=>['web']],函数(){} 我就是不明白为什么这不起作用 表格: <form action="{{ url('admin-backend/video') }}" me

我正在尝试使用Laravel 5.2通过表单上传视频和图像

当只上传图像时,它不会出现任何问题,但是当我尝试上传视频时,它只会在VerifyCsrfToken.php第67行中抛出标记不匹配异常

我的表单确实有隐藏的csrf_字段{!!csrf_字段()!!}并且我的路由在路由::组(['middleware'=>['web']],函数(){}

我就是不明白为什么这不起作用

表格:

    <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', 'adminVideoController@index');
    Route::get('/admin-backend/video/create', 'adminVideoController@create');
    Route::post('/admin-backend/video', 'adminVideoController@store');
    Route::get('/admin-backend/video/{id}', 'adminVideoController@show');
    Route::get('/admin-backend/video/{id}/edit', 'adminVideoController@edit');
    Route::put('/admin-backend/video/{id}', 'adminVideoController@update');
});
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;

}
控制器存储()方法:

    <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', 'adminVideoController@index');
    Route::get('/admin-backend/video/create', 'adminVideoController@create');
    Route::post('/admin-backend/video', 'adminVideoController@store');
    Route::get('/admin-backend/video/{id}', 'adminVideoController@show');
    Route::get('/admin-backend/video/{id}/edit', 'adminVideoController@edit');
    Route::put('/admin-backend/video/{id}', 'adminVideoController@update');
});
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;

}
视频型号:

    <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', 'adminVideoController@index');
    Route::get('/admin-backend/video/create', 'adminVideoController@create');
    Route::post('/admin-backend/video', 'adminVideoController@store');
    Route::get('/admin-backend/video/{id}', 'adminVideoController@show');
    Route::get('/admin-backend/video/{id}/edit', 'adminVideoController@edit');
    Route::put('/admin-backend/video/{id}', 'adminVideoController@update');
});
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;

}
protected$table='videos';
/**
*质量可分配的属性。
*
*@var数组
*/
受保护的$fillable=[
“名称”、“描述”、“功能”图像”、“图像1”、“图像”2”、“图像”3”、“图像”4”、“图像5”、“图像”6”、“视频”、“创建”处”、“更新”
];
/**
*@param$请求
*@return数组
*
*此函数通过将所有相关数据放入$fields数组来准备视频上载。
*它创建必要的文件夹结构来放置每次拍摄的图像和视频
*
*/
公共静态函数prepareVideoUpload($request)
{
$fields=[];//这将用于在数据库中存储信息,而不是请求
$fields['name']=$request['name'];
$fields['description']=$request['description'];
$videoPath=public_path()。/videos/'.substr(日期(“Y/m/d”),0,7);//videoPath看起来像-/Applications/MAMP/htdocs/website/public/videos/2016/04
$name=str_replace(“”,“-”,$request['name']);
$newVideoPath=$videoPath.'/'.$name;
//如果文件夹已经创建,只需创建新的视频名称文件夹
if(is_dir($videoPath)){
mkdir($newVideoPath);
}否则{
//创建文件夹结构/年/月/视频名称
mkdir($newVideoPath,0777,true);
}
//为个人拍摄创建视频和图像文件夹
mkdir($newVideoPath.'/video');
mkdir($newVideoPath.'/images');
//如果视频上载成功,请将其移动到images目录
if($request->hasFile('video')&$request->file('video')->isValid()){
$request->file('video')->move($newVideoPath.'/video',$request->file('video')->getClientOriginalName());
$fields['video']='videos/'.substr(日期(“Y/m/d”),0,7)。'/'.$name./video/'.$request->file('video')->getClientOriginalName();
}
//如果功能图像已成功上载,请将其移动到图像目录
如果($request->hasFile('feature\u image')&&&$request->file('feature\u image')->isValid()){
$request->file('feature_image')->move($newVideoPath.'/images',$request->file('feature_image')->getClientOriginalName());
$fields['feature_image']=“videos/”.substr(日期(“Y/m/d”),0,7)。“/”。$name./images/。$request->file('feature_image')->getClientOriginalName();
}
对于($i=1;$i<7;$i++){
//如果图像上载成功,请将其移动到图像目录
如果($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(日期(“Y/m/d”),0,7)。“/”。$name./images/。$request->file('image'.$i)->getClientOriginalName();
}
}
返回$fields;
}
到目前为止,我还没有做任何验证,因此当我尝试在没有视频的情况下上载时,它会工作并保存到文件夹中,并将文件夹路径输出到数据库中。但是,当我尝试上载视频时,它会抛出错误


我有点被困在这里了,有人有什么想法吗?

我猜您的POST数据达到了最大大小限制,这导致它只是删除输入

您可以将Web服务器和php调整到更高的限制,看看是否有帮助


php.ini中的
post_max_size
是一个很好的开始。

您是否在.env文件中生成并保存了唯一的APP_密钥?也可以尝试php artisan dump autoloadWhat是您的config/session.php
驱动程序
值?如果是文件,请确保同一文件中的
文件
路径正确,是的APP_密钥在.env f中生成ile和dump自动加载dit Nothing文件的正确pat是什么?“文件”=>存储路径(“框架/会话”),