PHP - error handling

0

I'm building an image upload system for my site. Performing tests with large files, I find the following warning :

  

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

Because the file has exceeded the limit size of the $ _POST variable.

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

    
asked by anonymous 10.02.2017 / 21:58

1 answer

0

You can get the 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 serve only to convert Max size to bytes, the secret is in the IF.

This answer and the other explanations are in link

    
10.02.2017 / 22:11