Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sonu's avatar
Level 3

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

0 likes
15 replies
Kryptonit3's avatar

AJAX uploading of a group of images individually, or all images posting at once in one request (redirect) with a normal POST?

1 like
Sonu's avatar
Level 3

@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 ?

nolros's avatar

@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.

1 like
Sonu's avatar
Level 3

@nolros i am already using this. My 4 images Uploaded But when I submit with the 5th image i got that error :(

Sonu's avatar
Level 3

@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>
Sonu's avatar
Level 3

All input fields with unique field name i have.

Kryptonit3's avatar

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.

1 like
Qlic's avatar

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.

1 like
Kryptonit3's avatar

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.

2 likes
finsok333's avatar

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

athulpraj's avatar

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

1 like

Please or to participate in this conversation.