表单提交 enctype 不等于 multipart/form-data 的时候
php.ini配置文件中,file_uploads = Off
上传的文件大小 > php.ini配置文件中所配置的最大上传大小时
只要出现 $_FILES 为
空数组
,就可能出现以上的问题,必须修复!php
若是
未选择任何文件
就立刻点击“上传按钮”
,$_FILES将会是一个有元素的数组
,元素中的每一个属性都是空字符串
,error属性为4
前端
array( 'filename' => array( 'name' => 'xxx.png', 'type' => 'image/png', 'size' => 2548863, 'tmp_name' => '/img/sdsdsd.png', 'error' => 0 ) )
不管是
单文件
仍是多文件上传
,都会有5个固定属性:name / size / type / tmp_name / error后端
相比
单文件上传
,多文件上传
处理起来要复杂多了数组
两种
多文件上传形式 //name相同 <form method="post" enctype="multipart/form-data"> <input type="file" name="wt[]"/> <input type="file" name="wt[]"/> <input type="submit" value="提交"/> </form> //name不一样(简单点) <form method="post" enctype="multipart/form-data"> <input type="file" name="wt"/> <input type="file" name="mmt"/> <input type="submit" value="提交"/> </form>
$_FILES
对应的数据结构不一样//name相同 array (size=1) 'wt' => array (size=5) 'name' => array (size=2) 0 => string '新建文本文档 (2).txt' (length=26) 1 => string '新建文本文档.txt' (length=22) 'type' => array (size=2) 0 => string 'text/plain' (length=10) 1 => string 'text/plain' (length=10) 'tmp_name' => array (size=2) 0 => string 'C:\Windows\php1D64.tmp' (length=22) 1 => string 'C:\Windows\php1D65.tmp' (length=22) 'error' => array (size=2) 0 => int 0 1 => int 0 'size' => array (size=2) 0 => int 0 1 => int 1820 //name不一样(简单点) array (size=2) 'wt' => array (size=5) 'name' => string '新建文本文档 (2).txt' (length=26) 'type' => string 'text/plain' (length=10) 'tmp_name' => string 'C:\Windows\php39C7.tmp' (length=22) 'error' => int 0 'size' => int 0 'mmt' => array (size=5) 'name' => string '新建文本文档.txt' (length=22) 'type' => string 'text/plain' (length=10) 'tmp_name' => string 'C:\Windows\php39D8.tmp' (length=22) 'error' => int 0 'size' => int 1820