Home > Backend Development > PHP Tutorial > 求指教,php处理多文件上传出错

求指教,php处理多文件上传出错

WBOY
Release: 2016-06-23 13:48:11
Original
962 people have browsed it

小弟初学php,在网上找了一段html上传多文件和php处理上传文件的代码,经调试,单文件上传没有问题,但多文件上传一直出错,不知错在哪里,求大虾指教
1. 上传代码

<body>   <form action="Test/ReceiveFile.php" method="post" name="upfile" enctype="multipart/form-data">    <input type="hidden" name="MAX_FILE_SIZE" value="9999999"/>	请选择文件的位置:<br />    <input name="myfile[]" type="file" id="myfile1" /><br />    <input name="myfile[]" type="file" id="myfile2" /><br />    <input name="myfile[]" type="file" id="myfile3" /><br />    <input name="myfile[]" type="file" id="myfile4" /><br />    <input name="myfile[]" type="file" id="myfile5" /><br />    <br />    <input type="submit" name="submit" value="上传" />   </form></body>
Copy after login

2. 服务端php代码
header('Content-Type:text/html;charset=utf-8');$fileArray = $_FILES['file'];//获取多个文件的信息,注意:这里的键名不包含[]$upload_dir = './upload/'; //保存上传文件的目录foreach ( $fileArray['error'] as $key => $error) {	if ( $error == UPLOAD_ERR_OK ) { //PHP常量UPLOAD_ERR_OK=0,表示上传没有出错		$temp_name = $fileArray['tmp_name'][$key];		$file_name = $fileArray['name'][$key];		move_uploaded_file($temp_name, $upload_dir.$file_name);		echo '上传[文件'.$key.']成功!<br/>';	}else {		echo '上传[文件'.$key.']失败!<br/>';	}}
Copy after login

3. 错误现象


回复讨论(解决方案)

$fileArray = $_FILES['file'] 改为$fileArray = $_FILES['myfile'] 

感谢小峰峰峡,问题解决了!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template