php多文件上传陷阱

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">

</script>

<style type="text/css">
</style>
</head>
    <body>
        <h2>多文件上传的表单陷阱</h2>
        <p>
        有时,我们为了方便上传多文件,在name的命名上,采用数组形式来命名<br />
        如pic[],pic[],pic[]
        </p>
        <form action="09.php" method="post" enctype="multipart/form-data">
            用户名:<input type="text" name="username" value="张三" /><br />
            头像:<input type="file" name="pic[0]" value="" /><br />
            艳照:<input type="file" name="pic[1]" value="" /><br />
            简历:<input type="file" name="pic[2]" value="" /><br />
            <input type="submit" value="提交" />
        </form>
    </body>
</html>




<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


print_r($_FILES);

/*
注意,多文件上传时,
如果name的名称是数组格式,
如 pic[],pic[]

形成的数组与 name=a,name=b这种形式不同
注意这个问题
Array
(
    [pic] => Array
        (
            [name] => Array
                (
                    [0] => Winter.jpg
                    [1] => Water lilies.jpg
                    [2] => Blue hills.jpg
                )

            [type] => Array
                (
                    [0] => image/jpeg
                    [1] => image/jpeg
                    [2] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [0] => D:\tmp\php709.tmp
                    [1] => D:\tmp\php70A.tmp
                    [2] => D:\tmp\php70B.tmp
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 0
                )

            [size] => Array
                (
                    [0] => 105542
                    [1] => 83794
                    [2] => 28521
                )

        )

)

*/




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值