2

I have a strange issue with laravel. I am working on a project with a file upload in it. everything works fine except for one pdf file i have on my machine. with that pdf file i get a TokenMismatchException. I tried it on an other projects and exactly the same error.

Here is my HTML:

<form method="POST" action="" enctype="multipart/form-data">
  {!! csrf_field() !!}
  <div class="form-group{{ $errors->has('file') ? ' has-error' : '' }} row">
      <label class="col-md-2 control-label" for="file">Bestand</label>
      <div class="col-md-4">
          <input type="file" name="file">
          @if ($errors->has('file'))
              <span class="help-block">
                  <strong>{{ $errors->first('file') }}</strong>
              </span>
          @endif
      </div>
  </div>
  <div class="row">
      <div class="pull-right">
          <button type="submit" class="btn btn-primary btn-orange">
              Opslaan
          </button>
      </div>
  </div>
</form>

And here is my route:

Route::post('footer-toevoegen', function () {
    dd(\Request::all());
});

And the pdf:

Here

Maantje
  • 1,781
  • 2
  • 20
  • 33
  • Your form does not have action URL – Emeka Mbah Mar 03 '16 at 12:24
  • @Digitlimit That is correct but the page the form is on is /footer-toevoegen. – Maantje Mar 03 '16 at 12:31
  • just to be sure set : `action = "/footer-toevoegen"` – Emeka Mbah Mar 03 '16 at 12:33
  • @Digitlimit Same result. – Maantje Mar 03 '16 at 12:35
  • have you checked the output of `{!! csrf_field() !!}` in your page -> view source code, to see whats there? – Emeka Mbah Mar 03 '16 at 12:36
  • @Digitlimit I have and it is being output correctly. Also it works fine with all files on my machine(images, other pdfs bigger and smaller, etc..) except for this pdf. – Maantje Mar 03 '16 at 12:39
  • Try `dd($_POST)` before the VerifyCsrfToken middleware runs. Perhaps something about the way that file is being encoded and delivered is messing up other post data. Or if you have xdebug, try setting a breakpoint before the csrf validation and going down the rabbit hole to see what's wrong. – Captain Hypertext Mar 03 '16 at 13:04
  • @CaptainHypertext Hmm $_POST is a empty array() with the pdf. Any ideas why this might hapen? – Maantje Mar 03 '16 at 13:40
  • @marsje Is the file a lot larger than others? What's your php config's `post_max_size` and `upload_max_filesize`? The upload could be failing silently because of that. – Captain Hypertext Mar 03 '16 at 18:50
  • @CaptainHypertext Sorry for the long silence the pdf is only 4mb and the max filesize in my ini is 64M. – Maantje Mar 07 '16 at 12:09
  • @marsje Hmm, I feel stupid, the file uploads would actually be in the $_FILES array, not $_POST. 2 more suggestions: are you developing in a local environment? Could you use something like xdebug to step through execution and look for more clues? Check if the file is saved in the temp location? Also, you could try recreating the pdf as a different file and try uploading that. – Captain Hypertext Mar 07 '16 at 13:23
  • @CaptainHypertext Thank you for helping me! I am developing on a local environment and when a part is finished i put it "online" on a staging environment for the client to see. Currently i don't have access to my working machine but ill check it first thing tomorrow morning. I never used xdebug but i can install it on my machine and try it out. – Maantje Mar 07 '16 at 19:48

1 Answers1

1

Can you check php.ini config ?

php.ini

post_max_size=20M
upload_max_filesize=20M
  • Sorry for the long silence the pdf is only 4mb and the max filesize in my ini is 64M I have other pdfs larger then the one that fails that do work. – Maantje Mar 07 '16 at 12:09