多文件上传

基于HTML5的多文件上传

html5的上传文件标签,支持multiple属性,可以使我们很方便的选择多个文件进行上传。

前台上传文件页面
index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多文件上传实例</title>
</head>
<body>
<div style="width: 800px;height: auto;">
    <div>
        <form action="upload.php" method="post" target="showInfo" enctype="multipart/form-data">
            <input type="file" name="files[]" multiple="multiple"/><input type="submit" value="上传">
        </form>
    </div>
    <div style="width: 100%;height: 200px;">
        <iframe name="showInfo" src="about:blank" width="100%" height="100%"></iframe>
    </div>
</div>
</body>
</html>

后台获取的$_FILES数组格式

array (size=1)
  'files' => 
    array (size=5)
      'name' => 
        array (size=2)
          0 => string 'QQ截图20161101202109.png' (length=26)
          1 => string 'test.html' (length=9)
      'type' => 
        array (size=2)
          0 => string 'image/png' (length=9)
          1 => string 'text/html' (length=9)
      'tmp_name' => 
        array (size=2)
          0 => string 'D:\wamp64\tmp\phpFC7C.tmp' (length=25)
          1 => string 'D:\wamp64\tmp\phpFC7D.tmp' (length=25)
      'error' => 
        array (size=2)
          0 => int 0
          1 => int 0
      'size' => 
        array (size=2)
          0 => int 3587
          1 => int 75

后台文件上传处理程序
upload.php

<?php
/**
 * Created by PhpStorm.
 * User: zhezhao
 * Date: 2016/11/2
 * Time: 9:45
 */
$res = [];
for($i=0;$i<count($_FILES["files"]["name"]);$i++){
    $tmp = explode(".",$_FILES["files"]["name"][$i]);
    $suffix_name = end($tmp);
    $path = __DIR__.DIRECTORY_SEPARATOR.time().".".$suffix_name;
    if(move_uploaded_file($_FILES["files"]["tmp_name"][$i],$path)){
        $res[] = $path;
    }
}
echo "upload ".count($res)." files.";
foreach ($res as $path){
    echo "<p>".$path."</p>";
}

这里写图片描述

基于FLASH的多文件上传

参考文档:

http://www.manongjc.com/article/222.html

http://www.uploadify.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值