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

KHAN's avatar
Level 4

TokenMismatchException when uploading large file size

Hey

Im using Laravel 5.2 andphp artisan servefor my php server.

Im trying to upload a pdf which is around 10mb. When i submit the form i get a TokenMismatchException error.

0 likes
5 replies
toniperic's avatar

This has something to do with how PHP works.

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty, thus it appears as if there's no CSRF token included in the request.

2 likes
KHAN's avatar
Level 4

@toniperic

Right, is there a way i can set the value, bearing in mind im using the inbuilt laravel server at the moment as my php server.

KHAN's avatar
KHAN
OP
Best Answer
Level 4

Even though im running php artisan serve. I can go into my etc/php/{version}/cli and update the values post_max_size and upload_max_filesize in the php.ini file.

This will fix it

1 like
chris_boudreaux's avatar

Changing those variables still results in the same csrf issue when someone loads anything larger than those new values, so how do we detect that the user loaded a file that was too large, and tell them so gracefully, to avoid the csrf error?

Please or to participate in this conversation.