源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP单文件和多文件上传实例

  • 时间:2021-04-28 05:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP单文件和多文件上传实例
[b]$_FILES何时为空数组?[/b] 表单提交 enctype 不等于 multipart/form-data 的时候 php.ini配置文件中,file_uploads = Off 上传的文件大小 > php.ini配置文件中所配置的最大上传大小时 只要出现 $_FILES 为空数组,就可能出现以上的问题,必须修复! 如果 未选择任何文件 就马上点击 “上传按钮”,$_FILES将会是一个有元素的数组,元素中的每个属性都是空字符串,error属性为4 [b]单文件上传 [/b] $_FILES 数据结构
array(
  'filename' => array(
    'name' => 'xxx.png',
    'type' => 'image/png',
    'size' => 2548863,
    'tmp_name' => '/img/sdsdsd.png',
    'error' => 0
  )
)
无论是[code]单文件[/code]还是[code]多文件上传[/code],都会有5个固定属性:name / size / type / tmp_name / error [b]多文件上传[/b] 相比单文件上传,多文件上传处理起来要复杂多了前端的两种多文件上传形式
//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>
后端的 [code]$_FILES[/code] 对应的数据结构不同
//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.
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部