Nathan Hornby
Nathan Hornby

Reputation: 1443

Getting a PHP error when I want a CodeIgniter error

I'm getting the following PHP error when attempting to upload a file that is too large:

POST Content-Length of 1034425027 bytes exceeds the limit of 33554432 bytes in Unknown

But I have the following set in my controller:

$config['max_size'] = '10000';

All the solutions I see involve increasing post_max_size etc… but I don't want to allow larger files to be uploaded - I want an error, just the CI one, not a PHP one I can do nothing with.

Any ideas? Is this just a flaw in PHP? I'd rather not process the 'false' return in the ajax as a file upload error, because technically that could be produced from any server error.

EDIT; To clarify, as I'm getting requests for code that won't shed any light on anything (I can only assume the question is being misunderstood):

If the file is between 10mb (the limit set by CI) and 32mb (the limit set by post_max_size) everything works fine - there is no code issue. But if the file is large than 32mb PHP catches the file before CI can parse it and provide me with proper errors, so I have no chance to properly flag large files unless I make post_max_size infinitely large - which seems both dangerous and flawed. I'm wondering if there's a way around this. Ideally I don't need the server to get involved until after the CI validation, as I'd rather flag a user friendly error than the POST to just die.

Upvotes: 2

Views: 538

Answers (2)

stormdrain
stormdrain

Reputation: 7895

Best bet would be to check the filesize with js [1] before attempting the upload. Short of this, the only options are to increase post size or create your own error hander [2].

[1] https://stackoverflow.com/a/7497439/183254

[2] http://www.php.net/manual/en/function.set-error-handler.php / https://stackoverflow.com/a/11745361/183254

Upvotes: 1

Sushil Kandola
Sushil Kandola

Reputation: 880

First increase the size in php.ini i.e. upload_max_size. By default PHP settings will be read by php code and then codeigniter settings. So increase the size from .ini file.

Upvotes: 0

Related Questions