Handling file uploads that exceed PHP's post_max_size?

126 views
Skip to first unread message

Jeffrey Zhao

unread,
Jan 9, 2017, 2:42:26 AM1/9/17
to f3-fra...@googlegroups.com
If I upload a file whose size exceeds post_max_size in php.ini, I get this error:
 
Internal Server Error
 
Fatal error: POST Content-Length of 18535303 bytes exceeds the limit of 8388608 bytes

From what I've googled, this is usually a warning instead of a fatal error, and can be handled with one of the solutions from this StackOverflow question. However, it seems that F3 terminates on receiving too large of a file immediately before any PHP code can be executed.

Is there a different way to handle large files in F3? Thanks.

ved

unread,
Jan 9, 2017, 5:31:57 PM1/9/17
to f3-fra...@googlegroups.com
As that SO thread already kind of states. Change the following values on your php.ini:

upload_max_filesize = 20M
post_max_size
= 20M

If you don't have access to your php.ini and are using apache, try the following on your .htaccess:

php_value upload_max_filesize 20M
php_value post_max_size
20M

Jeffrey Zhao

unread,
Jan 9, 2017, 8:26:27 PM1/9/17
to ved via Fat-Free Framework
However, if I upload an even larger file, F3 will still terminate and
throw a 500 internal server error. What I'm asking is, is there a way
to show my own error to the user before the 500 is thrown?

On Mon, Jan 9, 2017 at 5:31 PM, ved via Fat-Free Framework
<f3-framework+APn2wQdk8BzurMhBnm1...@googlegroups.com>
wrote:
> As that SO thread already kind of states. Change the following values on
> your php.ini:
>
> upload_max_filesize = 20M
> post_max_size = 20M
>
> If you don't have access to your php.ini and are using apache, try the
> following on your .htaccess:
>
> php_value upload_max_filesize 10M
> php_value post_max_size 10M
>
>
>
>
> On Monday, January 9, 2017 at 7:42:26 AM UTC, Jeffrey Zhao wrote:
>>
>> If I upload a file whose size exceeds post_max_size in php.ini, I get this
>> error:
>>
>>>
>>> Internal Server Error
>>
>>
>>>
>>> Fatal error: POST Content-Length of 18535303 bytes exceeds the limit of
>>> 8388608 bytes
>>
>>
>> From what I've googled, this is usually a warning instead of a fatal
>> error, and can be handled with one of the solutions from this StackOverflow
>> question. However, it seems that F3 terminates on receiving too large of a
>> file immediately before any PHP code can be executed.
>>
>> Is there a different way to handle large files in F3? Thanks.
>
> --
> -- You've received this message because you are subscribed to the Google
> Groups group. To post to this group, send an email to
> f3-fra...@googlegroups.com. To unsubscribe from this group, send an email
> to f3-framework...@googlegroups.com. For more options, visit this
> group at https://groups.google.com/d/forum/f3-framework?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Fat-Free Framework" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/f3-framework/SX51indvHHE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> f3-framework...@googlegroups.com.
> To post to this group, send email to f3-fra...@googlegroups.com.
> Visit this group at https://groups.google.com/group/f3-framework.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/f3-framework/fda8781c-4ad1-4331-937b-fd1d8f773c77%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jeffrey Zhao

unread,
Jan 9, 2017, 8:28:36 PM1/9/17
to Fat-Free Framework
However, if I upload an even larger file, F3 will still terminate and
throw a 500 internal server error. What I'm asking is, is there a way
to show my own error to the user before the 500 is thrown?

ved

unread,
Jan 9, 2017, 8:43:01 PM1/9/17
to Fat-Free Framework
That's maybe because the upload time is exceeding the max_execution_time parameter of php.ini which is usually 30s by default.

But there are a few other things that can be causing those issues (fastcgi paramters, webserver config, etc) 

Jeffrey Zhao

unread,
Jan 9, 2017, 8:44:13 PM1/9/17
to Fat-Free Framework
Thanks!

ikkez

unread,
Jan 10, 2017, 2:28:58 AM1/10/17
to f3-fra...@googlegroups.com
I think this can be solved with a custom error handler. Just have a look for the ERROR.text inside it, and if you find something about post_max_size, then don't halt execution, add a silent error and continue

$f3->set("ONERROR", function($f3, $params) {
  if (is_int(strpos($f3->{'ERROR.text'},'post_max_size') {
    // Don't stop here:
    $f3->HALT = false;
    return true;

  } else {
    // Process more serious problems:
    echo "Error: ".$f3->get('ERROR.text')."\n";
    $f3->HALT = true;
    return false;
  }
});

Reply all
Reply to author
Forward
0 new messages