PHP多文件上传

PHP多文件上传


<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8>
    <meta name=description content="">
    <meta name=viewport content="width=device-width, initial-scale=1">
    <title>多文件上传</title>
    <style>
        table tr td{width:200px;height:30px;}
        table tr{text-align:center;}
    </style>
</head>
<body>
    <form action="index.php" method="post" accept-charset="utf-8" enctype="multipart/form-data" name="form1">
        <table border="1">
            <tbody>
                <tr>
                    <td>内容1</td><td><input type="file" name="picture[]"></td>
                </tr>
                <tr>
                    <td>内容2</td><td><input type="file" name="picture[]"></td>
                </tr>
                <tr>
                    <td>内容3</td><td><input type="file" name="picture[]"></td>
                </tr>
                <tr>
                    <td>内容4</td><td><input type="file" name="picture[]"></td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td><input type="submit" name="submit" value="提交"></td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>
<?php
//判断服务器是否存在uploads文件,不存在则创建一个
    if(!is_dir("./uploads")){
        mkdir("./uploads");
    }
    //删除上传的图片重复的部分
    $array=array_unique($_FILES['picture']['name']);
    foreach ($array as $key => $value) {
       $path="uploads/".$value;
       if($value){
            if(move_uploaded_file($_FILES['picture']['tmp_name'][$key],$path)){
                $result=true;
            }else{
                $result=false;
            }
       }
    }

    if($result){
        echo "文件上传成功";
        echo "<meta http-equiv=\"refresh\" content=\";url=index.php\">";
    }else{
        echo "文件上传失败";
        echo "<meta http-equiv=\"refresh\" content=\";url=index.php\">";
    }
?>
posted @ 2019-01-01 21:32 栖息地 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值