Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POST Content-lLength of ... bytes exceeds the limit of 8388608 bytes in Unknown on line 0

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
NL
I am uploading multiple photos, where I want to reject photos that are too big, using essentially:

Code:
<form action='file_upload.php' method='POST' enctype='multipart/form-data'>
<input type='file' name='files[]' multiple>
</form>

file_upload.php contains:

Code:
foreach ($_FILES['files']['tmp_name'] as $key => $value) 
  {
  $file_tmpname = $_FILES['files']['tmp_name'][$key];
  $file_name = $_FILES['files']['name'][$key];
  $file_size = $_FILES['files']['size'][$key];
  }

This works fine if none of my photos are too big. I can detect an individual photo that is too big using $file_size, but if I have too many big photos I get the message in the title. I have found how to increase the limit of 8388608 bytes but I don't want to do this. I just want to abort neatly with a message like "too many big files".
 
Hi

To avoid abusively consuming the resources by uploading unacceptably huge files, that check is performed before preparing the files for processing by your script. So the error is generated automatically without a chance for the script to interfere.


Feherke.
feherke.github.io
 
Therefore I gather that there is no solution apart from telling the users not to upload large files as that will generate a fatal error.
 
Hi

My previous post was too short and too confusing. Let me try again.

When the upload size exceeds [tt]post_max_size[/tt], a startup error is raised. It can not be stopped by [tt]ini_set[teal]([/teal][green]'display_errors'[/green][teal],[/teal] false[teal])[/teal][/tt] and is too late for your script to stop it with [tt]ini_set[teal]([/teal][green]'display_startup_errors'[/green][teal],[/teal] false[teal])[/teal][/tt]. So you can turn if off only from the php.ini file.

When the upload size exceeds [tt]post_max_size[/tt], the entire POST data is purged. So if your [tt]form[/tt] had any other [tt]input[/tt], those will also disappear. However [tt]$_SERVER['CONTENT_LENGTH'][/tt] will still tell you how many data was originally submitted. So [tt]if [teal](![/teal] [navy]$_POST[/navy] [teal]&&[/teal] [navy]$_SERVER[/navy][teal][[/teal][green]'CONTENT_LENGTH'[/green][teal]] >[/teal] [purple]4096[/purple] [gray]/* HTTP headers included */[/gray][teal])[/teal] echo [green]"POST max size exceeded"[/green][teal];[/teal][/tt] is a pretty reliable way to display a relevant and more helpful error message.

If just some of the files are exceeding [tt]upload_max_filesize[/tt], then the $_POST will still be populated and only that single file's [tt]$_FILES[*]['error'][/tt] will be set to [tt]UPLOAD_ERR_INI_SIZE[/tt]. That should help you to tell apart the one big file and many almost big files cases.


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top