2

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.

Nathan Hornby
  • 1,423
  • 16
  • 32
  • why dont you try it by increasing the size in php ini – ɹɐqʞɐ zoɹǝɟ Feb 20 '14 at 12:00
  • Because I don't want the user to be able to upload larger files? And unless I can set it to 'unlimited' that wouldn't solve the issue. – Nathan Hornby Feb 20 '14 at 12:11
  • please, show your upload code. – Sena Feb 20 '14 at 12:17
  • Hi Sena, I'm not sure what I can show you that's of any interest. It's a pretty standard CI upload running through ajax. The problem is that the ajax is just getting a 'false' return, because PHP is producing an error before the upload code even has a chance to run. So I'm not able to get the 'max_size' error, because the user can always attempt to upload a file larger than the post_max_size (it doesn't matter what this is set to, a user could always attempt to upload a large file). – Nathan Hornby Feb 20 '14 at 12:28
  • You can show that you're loading the config correctly among other things. I don't get why people refuse to show the code they want help with... – stormdrain Feb 20 '14 at 14:14
  • I'm not refusing, I'm just not sure which bit would be relevant to the question or what it would demonstrate. The config is being loaded correctly, that isn't the issue, the issue is described in the question and relates to PHP flagging a file size problem before codeigniter even gets to execute its upload code. It's literally irrelevant. Uploading several pages of code will not make the question easier to answer and would only serve to confuse things further. – Nathan Hornby Feb 20 '14 at 14:37
  • Gotchya. Still helps to provide code (more == better) so people aren't chasing ghosts. – stormdrain Feb 20 '14 at 15:16

2 Answers2

1

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

Community
  • 1
  • 1
stormdrain
  • 7,915
  • 4
  • 37
  • 76
  • Ah, hadn't even thought of checking with JS first (I'm running through ajax anyway so this is a good option). I could at the very least check for files larger than the max post size, and let CI handle the rest. Thanks! – Nathan Hornby Feb 20 '14 at 15:37
0

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.

Sushil Kandola
  • 870
  • 2
  • 9
  • 22
  • So the max filesize in the CI settings is pointless? I could set the max_post_size to 1TB, but someone could still attempt to upload a file that's 1.1TB - and I have no facility to provide them with an error, PHP just fails. That doesn't seem right. – Nathan Hornby Feb 20 '14 at 12:10
  • @nathan CI Settings also matters a lot. PHP settings will be global everywhere in all projects. But CI setting will be only for CI specific project. – Sushil Kandola Feb 21 '14 at 03:47
  • If you are trying to upload more than PHP size, then it will fails and upload will not successful. Don't confuse in-between CI and PHP settings. Just Define Maximum size in PHP and CI as per your requirement. – Sushil Kandola Feb 21 '14 at 03:50
  • Think you're missing my point. I understand these things - but the CI settings become redundant if a user attempts to upload something bigger than the post_max_size setting. 'project by project' settings are only relevant if you have more than one service running on a machine - that's kind of a specific scenario. I don't mind that the upload cannot succeed, I don't want it to succeed, I jus want to be able to handle the error - which is impossible if the user attempts to upload something bigger than the post-max-size, as the server just falls over. That's bad design IMO. – Nathan Hornby Feb 21 '14 at 09:53
  • To clarify, in my mind the order should be reversed. Let the code (front-end and backend) handle things up until the point final checks are required. If Ci is set to 10mb and post_max_size is set to 32mb and a user attempts to upload a file that's 40mb, CI should be given the chance to handle that error before the server limits come into play, that should be a final check IMO. Of course that's not possible, but I was hoping to get around that flaw somehow. Increasing post_max_size does not fix that problem, unless it's set to ```infinite``` - which makes it redundant. – Nathan Hornby Feb 21 '14 at 09:59