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

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

WBOY
Release: 2016-06-13 12:07:21
Original
942 people have browsed it

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

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

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