zoukankan      html  css  js  c++  java
  • PHP实现多文件上传


    submit.html

    <html>
    <head>
        <meta charset="utf-8">
        <title>文件上传</title>
    </head>
    <body>
    
        <h1 style="color:white;background-color:#525D76;font-size:22px;text-align: center">文件上传</h1>
        <form action="upload.php" method="post" enctype="multipart/form-data">     <!--ENCTYPE="multipart/form-data"用于表单里有图片上传-->
        <input type="hidden" name="max_file_size" value="1000000"/>
        <table border="0">
        <tr>
            <th align="right" valign="top">上传文件:</th>
            <td>    
                <input type="file" name="fl[]" size:"60"><br/>   <!--可以将多个变量作为一个变量取得,可以使用"名称[]",这样变量的值就会以数组的形式被赋值-->
                <input type="file" name="fl[]" size:"60"><br/>
                <input type="file" name="fl[]" size:"60"><br/>
    
                <input type="checkbox" name="forbid" value="true"/>是否覆盖同名文件<br/>
                <input type="submit" name="" value="上传"/>
            </td>
        </tr>
        </table>
        </form>
    </body>
    </html>

    upload.php

    
    <html>
    <head>
        <meta charset="utf-8">
        <title>上传结果</title>
    </head>
    <body>
        <h1 style="color:white;background-color:#525D76;font-size:22px;text-align: center">上传结果</h1>
        <table border='1' width="350">
        <tr>
        <th>文件名</th><th>大小</th><th>MINE类型</th>
        </tr>
    
        <?php
        $path='./File/';//上传的地址
        $num=0;
    
        //求出文件个数,一个一个处理
    
        for ($i=0; $i < sizeof($_FILES['fl']['name']); $i++) { 
            $name = mb_convert_encoding($_FILES['fl']['name'][$i],'GB2312','UTF-8');  //将文件的文字码进行转换
    
            if($_FILES['fl']['name'][$i] == ''){
                continue;
            }//文件为空时,跳到下一个文件
    
            if(file_exists($path.$name) == TRUE&&$_POST['forbid'] == 'true'){
                $num++;
            }elseif (!is_uploaded_file($_FILES['fl']['tmp_name'][$i])) {
                $num++;
            }else{
        ?>
            <tr>
                <td align="right"><?php print($_FILES['fl']['name'][$i]);?></td>
                <td align="right"><?php print($_FILES['fl']['size'][$i]);?>byte</td>
                <td align="right"><?php print($_FILES['fl']['type'][$i]);?></td>
            </tr>
            <?php
                move_uploaded_file($_FILES['fl']['tmp_name'][$i],$path.$name);
            }
        }
        if($num>0){
            print('<div style="color:red">'.$num.'件上传失败</div>');
        }
        ?>
        </table>
    </body>
    </html>
    
    博客园:https://www.cnblogs.com/newtol 微信公众号:Newtol 【转发请务必保留原作者,否则保留追责权利】
  • 相关阅读:
    Python正课38 —— 有参装饰器
    Python正课37 —— 无参装饰器
    Python正课36 —— 闭包函数
    Python正课35 —— 函数对象与函数嵌套
    Python正课34 —— Global与Nonlocal
    Python正课33 —— 名称空间 与 作用域 介绍
    vue中wowjs的使用
    js得到时间戳(10位数)
    腾讯地图使用中,出现了“鉴权失败,请传入正确的key”
    js数组操作大全
  • 原文地址:https://www.cnblogs.com/newtol/p/10159138.html
Copyright © 2011-2022 走看看