Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP上传-当文件超过上传最大文件大小时,如何返回错误?_Php_.htaccess_File Upload - Fatal编程技术网

PHP上传-当文件超过上传最大文件大小时,如何返回错误?

PHP上传-当文件超过上传最大文件大小时,如何返回错误?,php,.htaccess,file-upload,Php,.htaccess,File Upload,当上载文件超过上传文件大小时,为什么会得到一个空数组而不是错误消息 我如何获得下面这样的错误代码1 1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 我已将最大上载限制设置为2MB英寸。htaccess: php_value post_max_size 2M php_value upload_max_filesize 2M 我的HTML表单: <form class="f

当上载文件超过上传文件大小时,为什么会得到一个空数组而不是错误消息

我如何获得下面这样的错误代码1

1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
我已将最大上载限制设置为2MB英寸。htaccess:

php_value post_max_size 2M
php_value upload_max_filesize 2M
我的HTML表单:

 <form class="form-submission" method="post" action="upload.php" enctype= "multipart/form-data">
    <input type="file" name="upload[]" id="input-file" multiple required>
    <button type="submit" class="btn btn-default no-gradient">Submit</button>
</form>
然后我尝试上传大于2MB的文件。结果是:

Array ( ) 
PHP没有错误。如何确保PHP返回错误?可能吗

如果我的upload.php中有:

print_r($_FILES);
print_r($_SERVER['CONTENT_LENGTH']);
我明白了:

6564878 // what is this mean??

错误出现在$\u文件['userfile']['error']中。您只需检查该值是否为UPLOAD\u ERR\u INI\u SIZE,以检测文件是否大于php.INI中定义的最大大小


希望有帮助。

空白数组与上载错误无关。检查您的代码,您可能在代码中有一些错误。@Alok我的代码中除了
print\r($\u文件)之外没有其他内容
$\u文件
为空,那么如何获取
$\u文件['userfile']['error']