gpt4 book ai didi

php - 上传大文件 laravel 5 时出现 token 不匹配异常

转载 作者:搜寻专家 更新时间:2023-10-31 21:02:13 26 4
gpt4 key购买 nike

当我尝试在 Laravel 5 中上传大文件时出现 token 不匹配错误。我在表单中使用了 token 字段。

TokenMismatchException in VerifyCsrfToken.php line 53:

我已经尝试了几种方法:

  1. 增加 upload_max_filesize 和 post_max_size。
  2. 更改 php.ini 文件并重新启动 apache 服务。
  3. 禁用该路由的 csrf 中间件,但在这种情况下不会获取文件!

这是我的看法:

<form id="csvform22345" role="form" class="form-horizontal" enctype="multipart/form-data" method="POST" action="{{ URL::to('admin/QC/uploadtomaindbcsv') }}">
{!! Form::token() !!}
{{--<input type="hidden" name="_token" value="{{ csrf_token() }}">--}}
<input type="hidden" name="pid" value="{{ $pid }}">
<div class="row">
<div class="col-sm-8">
<label class="control-label">Select File</label>
<input id="csvfile2" type="file" name="file2" required class="file-loading">
</div>
<div class="col-sm-4">
<div class="alert alert-info small mar-top">Only .csv files allowed.</div>
</div>
</div>
</form>

Controller 函数:

    public function upload_to_maindb()
{
try
{
ini_set('upload_max_filesize', '2G');
ini_set('post_max_size', '4G');
ini_set('max_execution_time', '5000000');
ini_set('max_input_time', '5000000');
ini_set('memory_limit', '200M');
//echo "try block" ; die;
$now = new DateTime();

$timestamp = $now->format('Y-m-d H:i:s');
$pid = Input::get('pid');
$file = Input::file('file2');
$project = Projects::select('project_type')->where('project_id',$pid)->get()->first();
$pt = $project->project_type;
if($file !='') {
$pid = Input::get('pid');
$fp = fopen($file, 'r');
//echo "its here";
//die;
$datas = array();
unset($datas);

while (($row = fgetcsv($fp)) !== FALSE) {
$contact['company_name'] = $row[0];
$contact['website'] = $row[1];
$contact['contact_name'] = $row[2];
$contact['first_name'] = $row[3];
$contact['last_name'] = $row[4];
$contact['email'] = $row[5];
$contact['title'] = $row[6];
$contact['address'] = $row[7];
$contact['city'] = $row[8];
$contact['state'] = $row[9];
$contact['zip_code'] = $row[10];
$contact['country'] = $row[11];
$contact['phone_number'] = $row[12];
$contact['fax_number'] = $row[13];
$contact['industry'] = $row[14];
$contact['sub_industry'] = $row[15];
$contact['revenue'] = $row[16];
$contact['employees'] = $row[17];
$contact['data_category'] = $pt;
/*
$contact['sic_code'] = $row[18];
$contact['naics_code'] = $row[19];
$contact['linkedin_source'] = $row[20];
*/
$contact['last_updated_via_project_id'] = $pid;
$datas[] = $contact;
}
foreach (array_chunk($datas, 200) as $data) {
Master_datarecords::insertIgnore($data);
}
}
unset($datas);
//echo "done"; die;
$msg= "successfully inserted";
}
catch(\Exception $e)
{
$msg = "some error occured, please check the file.";
}

$approved_projects= array();
$pids= array();
$i=0;
$projstat = ProjectuserHelpers::GetProjectStatusId("approved");
$projects_object=Projects::where('project_status',$projstat)->get();
if(!($projects_object->isEmpty())) {
$projects = $projects_object->toArray();
foreach ($projects as $val) {
$approved_projects[$i]['pid'] = $val['project_id'];
$approved_projects[$i]['projectname'] = $val['project_name'];
$approved_projects[$i]['record_count'] = Transitional_records::where('fk_project_id', $val['project_id'])->count();
$i++;
}
}
return View::make('admin/home_page/QC/QCtomaindb',compact('approved_projects','msg'));
}

除了这些我在互联网上找不到任何东西。还有其他解决方案吗?

最佳答案

我认为这是由于 post_max_size 限制而发生的。

我将它增加了 50M 并且还增加了上传最大文件大小。

现在可以了。

关于php - 上传大文件 laravel 5 时出现 token 不匹配异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39785495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com