<!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
)
)
)
*/