php - Laravel 5 TokenMismatchException on Multiple file uploads -
in laravel 5 application, there provision made admin upload product image , product's pdf file. so, form has 2 input fields this:
<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>
when upload image , leaflet both less 2mb, gets uploaded successfully. when using, leaflet more 2mb, tokenmismatchexception @ line 46
in php.ini
file located @ /etc/php5/apache2/php.ini
have configuration so:
; maximum allowed size uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 2g ; maximum size of post data php accept. ; value may 0 disable limit. ignored if post data reading ; disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 6g
the files uploading (working):
- image: name: flower-1.jpg, size:
51.6kb
- pdf: name: productinfo.pdf, size:
777.2kb
the files uploading (not working - gives tokenmismatchexception @ line 46 in verifycsrftoken.php):
- image: name: flower-1.jpg, size:
51.6kb
- pdf: name: productinfo-1.pdf, size:
5.00mb
the controller
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 updated.'); return redirect()->back(); } /** * coming 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 $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); }
edit 1: using form model binding
, both create
, edit
file has same form:
<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>
edit 2: information, using lamp on ubuntu 14.04 lts x64-bit architecture. it's localhost. have not hosted application yet.
kindly me out. thanks.
i had same issue , able solve increasing upload_max_filesize , post_max_size php settings. former should bigger individual files uploading , latter should bigger total of 2 (or more) files being uploaded.
there's better explanation of $_post variable leads presenting token mismatch exception here:
http://laravel.io/forum/02-20-2014-l40-csrf-tokenmismatchexception-when-uploading-large-files
hopefully works if haven't solved already!
Comments
Post a Comment