title: Laravel 5.5 - Allowed memory size of 134217728 bytes exhausted (tried to allocate 60067000 bytes)
body: <p>This question builds on my <a href="https://stackoverflow.com/questions/46326647/laravel-5-5-handling-posttoolargeexception-for-large-base64-image">previous question</a>.</p>
  
  <p>Basically, we upload a base64 image that is 50MB, when we have a hard limit of 10MB per image. Anything greater than 10MB should be detected before the php.ini memory limit is hit, so we can return an image is too big error to the user.</p>
  
  <p>I know this would work:</p>
  
  <p><code>ini_set('memory_limit', '-1');</code></p>
  
  <p>But is a bad way to handle the problem. The user can send a file that's 1GB+ and my server will choke. I am looking for a solution to detect that the file is over the size limit <strong>without</strong> increasing the <code>memory_limit</code>, but determining it is over the 10MB limit as soon as possible so we can return a graceful error.</p>
  
  <p>The solution in the previous question does not ever get reached since the <code>memory_limit</code> gets hit and returns the log error before anything in the controller gets to run.</p>
  
  <p>Any idea how to solve this?</p>