AJAX uploading of a group of images individually, or all images posting at once in one request (redirect) with a normal POST?
At Multiple Image Uploading TokenMismatchException in VerifyCsrfToken.php line 46:
I got this error when i try to upload more then 4 images at a page.
TokenMismatchException in VerifyCsrfToken.php line 46:
Why i am getting this error ? If if seprately upload image they easily uploaded
@Kryptonit3 Sorry i don't understand. I am not using Ajax a form with browse button and Method Using Post. So what was the role of Ajax there ?
Was just wondering if you were just using a basic form to POST the data or if you were doing it via an AJAX request. The fact you do not understand leads me to believe that it is just a normal form POST.
Are you using Dropzone for your multi-upload?
If so look at this - http://laravel.io/forum/04-17-2014-tokenmismatchexception-with-dropzonejs
@Kryptonit3 No i am not using dropzone .Not Special MultiUpload Just Browse Button
Please Have A Look http://screencast.com/t/tUnvaJiI6rX
@Sonu try add 'enctype' => 'multipart/form-data' to form open. Example, below:
{!! Form::open(['route' => 'postFileUpload', 'files' => true, 'method' => 'POST', 'enctype' => 'multipart/form-data', 'name' => 'mmeForm']) !!}
If that doesn't work post code to take a look.
@nolros i am already using this. My 4 images Uploaded But when I submit with the 5th image i got that error :(
@sonu How is the input for the files in the form ?
@bestmomo Here are these
<div class="form-group ">
<label for="cname" class="control-label col-lg-2">Description Image 1 </label>
<div class="col-lg-10">
<input name="file1" type="file" id="exampleInputFile">
<p class="help-block">Image Size 400x300 px.</p>
</div>
</div>
All input fields with unique field name i have.
If all input images are the same then submit them as an array and loop over them in your logic.
<div class="form-group ">
<label for="cname" class="control-label col-lg-2">Description Image 1 </label>
<div class="col-lg-10">
<input name="file[]" type="file" id="exampleInputFile">
<p class="help-block">Image Size 400x300 px.</p>
</div>
</div>
<div class="form-group ">
<label for="cname" class="control-label col-lg-2">Description Image 2 </label>
<div class="col-lg-10">
<input name="file[]" type="file" id="exampleInputFile">
<p class="help-block">Image Size 400x300 px.</p>
</div>
</div>
<div class="form-group ">
<label for="cname" class="control-label col-lg-2">Description Image 3 </label>
<div class="col-lg-10">
<input name="file[]" type="file" id="exampleInputFile">
<p class="help-block">Image Size 400x300 px.</p>
</div>
</div>
then
if($request->hasFile('file'))
{
foreach($request->file('file') as $file)
{
}
}
or something similar. untested. to make sure there isn't an issue in your file naming or logic.
I have the same thing, using a regular form (no AJAX), including files => true in the form open command, and having a file[] array it gives a _token mismatch error when i select more than 3 or 4 images at the same time.
are you using the Form builder or coding it in HTML yourself? Just want to make sure the _token is getting added. If you use the form builder this is done automatically. If you are using plain HTML you will need to include token in hidden element.
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
Also, if you upload more then your server's post_max_size setting (php setting) the input will be empty (gets erased because your upload exceeds the setting limit), hence a token miss-match
so if you have 2 upload input's in your form and your upload_max_filesize is 2G, your post_max_size needs to be at least 4G
I would recommend increasing that php setting.
It kinda makes sense as to why 2 or so files upload fine, they; consolidated total file size of all files; do not exceed the set limit. But when you do 3 or more, you exceed the limit, so server flushes the POST and GET and throws error. You may even have a related error in your apache/nginx error log.
upload_max_filesize is the limit of any single file.
post_max_size is the limit of the entire body of the request, which could include multiple files.
@Kryptonit3 Thanks for that usefull info i check that out
I had a same issue but changing the upload_max_filesize and post_max_size solved my problems..Thank you @Kryptonit3...That was a very useful information
adding the following to the .htaccess file
php_value post_max_size 200M
php_value upload_max_filesize 250M
php_value max_execution_time 6000000
php_value max_input_time 6000000
php_value memory_limit 250M
worked for me
Please or to participate in this conversation.