在我Laravel 5的应用,存在用于管理员上传的产品形象和产品的PDF文件制作。所以,形式有2个输入字段这样的:Laravel 5 TokenMismatchException对多文件上传
<div class="col-md-4 col-sm-6">
<div class="form-group">
{!! Form::label('image', 'Image File:') !!}
{!! Form::file('image', ['class' => 'form-control input-sm']) !!}
</div>
</div>
<div class="col-md-4 col-sm-6">
<div class="form-group">
{!! Form::label('leaflet', 'Leaflet:') !!}
{!! Form::file('leaflet', ['class' => 'form-control input-sm']) !!}
</div>
</div>
当我上载超过2MB的图像和单张都不到,它就会被上传成功。但在使用时,小叶大于2MB,我得到TokenMismatchException at line 46
在我php.ini
文件,该文件位于/etc/php5/apache2/php.ini
我的配置如下所示:
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2G
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 6G
,我上传的是文件(工作):
- 图片:名称:花1.JPG,尺寸:
51.6kb
- PDF:名称:productInfo.pdf,尺寸:
777.2kB
,我上传的文件(不工作 - 在VerifyCsrfToken.php在第46行给出TokenMismatchException):
- 图片:名称:花1.JPG,尺寸:
51.6kb
- PDF:名称:productInfo-次数1.pdf,尺寸:
5.00MB
控制器
public function update($id, UpdateProductRequest $request) {
$product = $this->prod->findProductById($id);
$this->prod->updateProductOfId($product->id, $request);
Flash::success('product_general_info_updated', 'The product general information has been successfully updated.');
return redirect()->back();
}
/**
* Coming from ProductRespository.php
*/
public function updateProductOfId($id, Request $request)
{
$prd = $this->findProductById($id);
$getAllInput = $request->all();
if($request->file('image'))
{
$imageType = array(
'product' => array(
'height' => 347,
'width' => 347
),
'category' => array(
'height' => 190,
'width' => 190
)
);
$imageFileName = $request->file('image')->getClientOriginalName();
foreach ($imageType as $key => $value)
{
$currentFile = Input::file('image');
$fileName = $currentFile->getClientOriginalName();
$image = Image::make($request->file('image'));
$name = explode('.', $fileName);
$destinationPath = public_path().'/images/products/uploads';
if ($key === 'product') {
$image->resize($value[ 'width' ], $value[ 'height' ]);
$image->save($destinationPath . '/' . $name[ 0 ] . "-" . $value[ 'width' ] . "-" . $value[ 'height' ] . ".jpg", 100);
} elseif ($key === 'category') {
$image->resize($value[ 'width' ], $value[ 'height' ]);
$image->save($destinationPath . '/' . $name[ 0 ] . "-" . $value[ 'width' ] . "-" . $value[ 'height' ] . ".jpg", 100);
}
}
$getAllInput['image'] = $imageFileName;
}
if($request->file('leaflet'))
{
$currentFile = Input::file('leaflet');
$fileName = $currentFile->getClientOriginalName();
$destinationPath = public_path().'/leaflets/products/uploads';
$currentFile->move($destinationPath, $fileName);
$getAllInput['leaflet'] = $fileName;
}
return $prd->update($getAllInput);
}
编辑1: 我使用Form Model Binding
,这样既create
和edit
文件具有相同的形式:
<div class="container">
@include('errors.list')
{!! Form::open(['url' => '/admin/products', 'autocomplete' => 'off', 'files' => true]) !!}
@include('admin.products.product_general_form', ['submitButtonText' => 'Add Product'])
{!! Form::close() !!}
</div>
编辑2: 只是为了信息,我在Ubuntu 14.04 LTS x64位架构上使用LAMP。这是一个本地主机。我还没有托管该应用程序。
请帮助我。谢谢。
您可以在您的视图中打开表单的位置添加代码吗? –
您是否使用Former处理您的表单?我无法理解你如何将文件上传到2 MB,但不能再更新。你在这里使用什么网络服务器? (抱歉回答迟了) –
您是否尝试过类似'ini_get('upload_max_filesize')'来检查您的最大上传文件大小是否已由conf文件正确设置? –