PHP单文件和多文件上传实例
2017-12-12 16:09
495 查看
$_FILES何时为空数组?
表单提交 enctype 不等于 multipart/form-data 的时候 php.ini配置文件中,file_uploads = Off 上传的文件大小 > php.ini配置文件中所配置的最大上传大小时
只要出现 $_FILES 为空数组,就可能出现以上的问题,必须修复!
如果 未选择任何文件 就马上点击 “上传按钮”,$_FILES将会是一个有元素的数组,元素中的每个属性都是空字符串,error属性为4
单文件上传
$_FILES 数据结构
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
字段Error用途
值:1 上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。
值:2 上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。
值:3 文件只有部分被上传。
值:4 没有文件被上传。值:5 上传文件大小为0.
相关文章推荐
- PHP学习实例—3(文件的上传与下载)
- php jquery 多文件上传简单实例
- php实例四之文件的上传
- php文件上传的简单实例
- php多个文件及图片上传实例详解
- php+ajax实现图片文件上传实例代码
- php+ajax实现图片文件上传功能实例
- PHP文件上传实例
- php使用AjaxFileUpload上传图片文件实例
- 基于Ajax+PHP的单文件、多文件异步上传实例
- php封装的单文件(图片)上传类完整实例
- PHP入门教程之上传文件实例详解
- php 文件上传实例
- PHP文件上传实例附详解
- php上传文件,创建递归目录的实例代码
- PHP文件上传实例详解!!!
- php图片文件上传实例代码
- php实现图片上传与文件上传的实现代码实例
- 【代码】PHP 文件上传实例
- php上传文件分类实例代码