index.php页面表单页面

<formaction="test.php"method="post"enctype="multipart/form-data">name:<inputtype="text"name="username"value=""/><br/><inputtype="hidden"name="MAX_FILE_SIZE"value="1000000"/>uppic:<inputtype="file"name="picture[]"value=""/><br/>uppic:<inputtype="file"name="picture[]"value=""/><br/>uppic:<inputtype="file"name="picture[]"value=""/><br/><inputtype="submit"value="upload"/><br/></form>

test.php页面 处理提交信息页面

<?phpheader('content-type:text/html;charset=utf-8');//var_dump($_POST);//var_dump($_FILES);/**单个文件上传*array(size=2)'username'=>string'yang'(length=4)'MAX_FILE_SIZE'=>string'1000000'(length=7)array(size=1)'picture'=>array(size=5)'name'=>string'PHP.jpg'(length=7)'type'=>string'p_w_picpath/jpeg'(length=10)'tmp_name'=>string'D:\wamp\tmp\php7C.tmp'(length=21)'error'=>int0'size'=>int279468**多个文件上传*array(size=2)'username'=>string'xiaohua'(length=7)'MAX_FILE_SIZE'=>string'1000000'(length=7)array(size=1)'picture'=>array(size=5)'name'=>array(size=3)0=>string'PHP.jpg'(length=7)1=>string'PHP.jpg'(length=7)2=>string'PHP.jpg'(length=7)'type'=>array(size=3)0=>string'p_w_picpath/jpeg'(length=10)1=>string'p_w_picpath/jpeg'(length=10)2=>string'p_w_picpath/jpeg'(length=10)'tmp_name'=>array(size=3)0=>string'D:\wamp\tmp\php89.tmp'(length=21)1=>string'D:\wamp\tmp\php8A.tmp'(length=21)2=>string'D:\wamp\tmp\php8B.tmp'(length=21)'error'=>array(size=3)0=>int01=>int02=>int0'size'=>array(size=3)0=>int2794681=>int2794682=>int279468**/$num=count($_FILES['picture']['name']);for($i=0;$i<$num;$i++){//设置多个文件上传//第一步:判断错误if($_FILES['picture']['error'][$i]>0){switch($_FILES['picture']['error'][$i]){case1:echo'上传的文件超过了php.ini中upload_max_filesize选项限制的值。';break;case2:echo'上传文件的大小超过了HTML表单中MAX_FILE_SIZE选项指定的值。';break;case3:echo'文件只有部分被上传。';break;case4:echo'没有文件被上传。';break;case6:echo'找不到临时文件夹。';break;case7:echo'文件写入失败。';break;default:echo'未知错误';}//exit;continue;}//第二步判断类型$arr=explode(".",basename($_FILES['picture']['name'][$i]));$ext=array_pop($arr);$allowType=array("gif","png","jpg","jpeg");if(!in_array($ext,$allowType)){echo'上传的类型不合法';exit;}//第三步判断大小$maxsize=1000000;if($_FILES['picture']['size'][$i]>$maxsize){echo"上传的文件超过最大存储值{$maxsize}字节";exit;}//第四步上传后的文件名一定要设置随机文件名$tmpfile=$_FILES['picture']['tmp_name'][$i];$destname="./uploads/".date('YmdHis').rand(99,99999).".".$ext;//设置随机文件名//将临时目录下的上传的文件,复制到指定的新目录,就算上传成功。if(move_uploaded_file($tmpfile,$destname)){echo"上传成功!";}else{echo"上传失败!";}}