PHP - error handling

Asked

Viewed 108 times

0

I am building a system of sending images to my website. Performing tests, with large files, I come across the following warning:

POST Content-Length of 9489104 bytes Exceeds the limit of 8388608 bytes in

Why the file exceeded the limit size of the $_POST variable.

My question is how I can treat this error, with a message like "very large file", to the user, without this error appearing to him?

1 answer

0


You can pick it up by content lenght:

<?php

if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) &&
     empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0 )
{      
  $displayMaxSize = ini_get('post_max_size');

  switch ( substr($displayMaxSize,-1) )
  {
    case 'G':
      $displayMaxSize = $displayMaxSize * 1024;
    case 'M':
      $displayMaxSize = $displayMaxSize * 1024;
    case 'K':
       $displayMaxSize = $displayMaxSize * 1024;
  }

  $error = 'Posted data is too large. '.
           $_SERVER['CONTENT_LENGTH'].
           ' bytes exceeds the maximum size of '.
           $displayMaxSize.' bytes.";
}

?>

The cases are only used to convert Max size to bytes, the secret is in IF.

This answer and the other explanations are in link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.