PHP:超大文件上传失败超过post_max_size失败

时间:2017-12-22 03:34:11

标签: php file-upload

我正在尝试捕获超大文件上传的错误。

我的限制(表格中的MAX_FILE_SIZE以及稍后的$ _FILES ['uploadFile'] ['size'])是10Mb / 10485760字节

在php.ini中,我有:

  • post_max_size = 30M
  • upload_max_filesize = 20M

每次我在10M(限制)和post_max_size(30M)之间上传时,都会发现错误,但是当它超过30M时,会直接回到家庭地址(在我的情况下:{ {3}}),没有记录任何错误。

这是我的HTML代码:

<form class="form-horizontal" action="./skrip.php" method="post" name="thisForm" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10485760">
<label>Upload file</label>
<input class="upload" type="file" name="uploadFile" class="file" id="uploadFile">
<button>Submit</button
</form>

这是我的skrip.php

$displayMaxSize = ini_get('post_max_size') * 1024 * 1024;

if (  $_SERVER['CONTENT_LENGTH'] > $displayMaxSize
   || $_FILES['uploadFile']['size'] > 10485760) {
    throw new Exception('PHP discarded POST data because of request exceeding post_max_size.');
}

... continue to file validation

我尝试接受以下SO帖子的回答,但仍然失败:

http://project.dev/admin/

PHP Warning: POST Content-Length of n bytes exceeds the limit of 3145728 bytes in Unknown on line 0

How to gracefully handle files that exceed PHP's `post_max_size`?

0 个答案:

没有答案