PHP - empty $_POST and $_FILES - when uploading larger files

前端 未结 5 1577
深忆病人
深忆病人 2020-11-29 04:18

I have a following problem, I have HTML form that uploads a file with some extra information. But it allows to upload files that only less then 10MB. But when user tries to

相关标签:
5条回答
  • 2020-11-29 04:19

    As noted in the edited question $_POST and $_FILES are empty when PHP silently discards data (happens when the actual data is bigger than post_max_size). Since HTTP header and $_GET remain intact those can be used to detect the discards.

    Option a)

    if(intval($_SERVER['CONTENT_LENGTH'])>0 && count($_POST)===0){
        throw new Exception('PHP discarded POST data because of request exceeding post_max_size.');
    }
    

    Option b)
    Add a GET parameter that tells whether POST data is present.

    0 讨论(0)
  • 2020-11-29 04:23

    i can mention that if you process form like below

    if(isset($_POST['submit'])
    

    if post_max_size is lower than posted data then the $_POST['submit'] will be empty

    0 讨论(0)
  • 2020-11-29 04:26

    Run phpinfo() and check to make sure your upload_max_filesize and post_max_size directives are large enough.

    http://us.php.net/manual/en/ini.core.php#ini.upload-max-filesize

    http://us.php.net/manual/en/ini.core.php#ini.post-max-size

    0 讨论(0)
  • 2020-11-29 04:42

    You can check for upload errors with:

    if ($_FILES['images']['error'] !== UPLOAD_ERR_OK) {
       die("Upload failed with error code " . $_FILES['images']['error']);
    }
    

    The error codes are defined here.

    0 讨论(0)
  • 2020-11-29 04:44

    There are some limits - both on client and server side.

    On client side, the MAX_FILE_SIZE field is not of much use, perhaps browser may take it as a hint; but rather browsers follow their configured limits.

    On server side, check php.ini for:

    upload_max_filesize = 5M
    
    post_max_size = 5M 
    
    max_input_time = ...
    

    Also check Apache's log for notes about dropped POST body or such.

    0 讨论(0)
提交回复
热议问题