多文件上传

来源:互联网 发布:网络诈骗 刑事立案 编辑:程序博客网 时间:2024/05/16 07:21

基于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
原创粉丝点击