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

octoxan's avatar

TokenMismatchException only on certain file upload?

Has anyone ever seen a "TokenMismatchException in VerifyCsrfToken.php line 68:" error being thrown only on a certain file upload?

I have an import script in a controller which takes an imported .xlsx file and turns it into database data, and it's worked fine up until this point. But now I've gotten one file I need to import and just this file throws the TokenMismatchException error.

Yes, the CSRF token is there, and this isn't being done over ajax. Only one file throws this error.

Banging my head against a wall here because as far as I can tell the file looks fine, data just like others that have worked.

0 likes
6 replies
sid405's avatar

It happens only with this one file? Even on consecutive attempts but it's ok if you change files? Is this the idea?

octoxan's avatar

Yep, and that's the only error it throws. There's no way it could actually have anything to do with the CSRF token if it works with other files, right?

sid405's avatar

No, not really. What are you using to Import it? is it LaravelExcel or something? Also, is there really nothing particular about this file?

Could you export its data into another file and try that? Sometimes excel files have some nasty-a** formatting that gets in the way.

octoxan's avatar

Yeah it's LaravelExcel. I'll try just copying it all to a new file first

Snapey's avatar
Snapey
Best Answer
Level 122

it happens when your file is smaller than the max upload size but more than the max post size. The input is truncated at the max post size which means that the csrf token is lost

4 likes

Please or to participate in this conversation.