入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

综合运用数组函数-实现多文件上传 CH7--数组p126

创建时间:2016-12-19 投稿人: 浏览次数:242
index.php   
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>综合运用数组函数-实现多文件上传</title>
<style type="text/css">
<!--
body {
	background-color: #F0F0F0;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {
	font-size: 13px;
	font-weight: bold;
}
.STYLE2 {font-size: 12px;
color: #FF0000;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
-->
</style></head>

<body>
<table width="725" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2"><img src="images/02-03.jpg" width="765" height="230"></td>
  </tr>
  <tr>
    <td width="662" align="center" valign="top"><table width="578" border="0" cellspacing="0" cellpadding="0">
      
      <tr>
        <td height="20" colspan="2" align="center" bgcolor="#FFFFFF"><img src="images/02-03 (1).jpg" width="561" height="42"></td>
        </tr>
      <tr>
        <td height="20" colspan="2" align="center" bgcolor="#FFFFFF" class="STYLE1">文件路径(5个文件以内任意上传)</td>
        </tr>
      <form action="index_ok.php" method="post" enctype="multipart/form-data" name="form1">
        <tr>
          <td width="88" height="30" align="right" class="STYLE1">内容1:</td>
          <td width="369"><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">内容2:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">内容3:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">内容4:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
        </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">内容5:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="50"> </td>
          <td><input type="image" name="imageField" src="images/02-03 (3).jpg"></td>
          </tr>
      </form>
    </table></td>
    <td width="99"><img src="images/02-03 (2).jpg" width="204" height="362"></td>
  </tr>
  <tr>
    <td colspan="2"><img src="images/02-03 (4).jpg" width="765" height="80"></td>
  </tr>
</table>
<p> </p>
</body>
</html>
<?php  
	if(!is_dir("./upfile")){ 							//判断服务器中是否存在指定文件夹
		mkdir("./upfile");								//如果不存在,则创建文件夹
	}
	//var_dump($_FILES);exit;
	array_push($_FILES["picture"]["name"],"");			//向表单提交的数组中增加一个空元素   
    $array=array_unique($_FILES["picture"]["name"]);    //删除数组中重复的空数组,重复的文件;
    array_pop($array);             						//删除数组中最后一个单元
	for($i=0;$i<count($array);$i++){					//根据元素个数执行for循环
    	$path="upfile/".$_FILES["picture"]["name"][$i];	//定义上传文件存储位置
		if(move_uploaded_file($_FILES["picture"]["tmp_name"][$i],$path)){	//执行文件上传操作
			$result=true;
		}else{
			$result=false;
		}
	}
	if($result==true){
			echo "文件上传成功,请稍等...";
			echo "<meta http-equiv="refresh" content="3; url=index.php">";
		}else{
			echo "文件上传失败,请稍等...";
			echo "<meta http-equiv="refresh" content="3; url=index.php">";
	}
/*
array
  "picture" => 
    array
      "name" => 
        array
          0 => string "QQ截图20160424193612.png" (length=24)
          1 => string "pwd.txt" (length=7)
          2 => string "" (length=0)
          3 => string "" (length=0)
          4 => string "" (length=0)
      "type" => 
        array
          0 => string "image/png" (length=9)
          1 => string "text/plain" (length=10)
          2 => string "" (length=0)
          3 => string "" (length=0)
          4 => string "" (length=0)
      "tmp_name" => 
        array
          0 => string "E:wamp	mpphp2FFE.tmp" (length=23)
          1 => string "E:wamp	mpphp2FFF.tmp" (length=23)
          2 => string "" (length=0)
          3 => string "" (length=0)
          4 => string "" (length=0)
      "error" => 
        array
          0 => int 0
          1 => int 0
          2 => int 4
          3 => int 4
          4 => int 4
      "size" => 
        array
          0 => int 47634
          1 => int 209
          2 => int 0
          3 => int 0
          4 => int 0
 */
?>




声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。