Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
<?php if (isset($_FILES['upload_file'])) { echo '<pre>'; print_r($_FILES); echo '</pre>'; if (count($_FILES['upload_file']['error']) > 1) { echo '上传了多个文件<br>'; foreach ($_FILES['upload_file']['error'] as $key => $value) { if ($value == UPLOAD_ERR_OK) { echo move_uploaded_file($_FILES['upload_file']['tmp_name'][$key], "./uploade/{$_FILES['upload_file']['name'][$key]}") ? "文件{$_FILES['upload_file']['name'][$key]}移动成功<br>" : "文件{$_FILES['upload_file']['name'][$key]}移动失败<br>"; } else { echo '文件上传失败<br>'; } } } elseif (count($_FILES['upload_file']['error']) === 1) { if ($_FILES['upload_file']['error'][0] == 4) { echo '文件未上传<br>'; } elseif ($_FILES['upload_file']['error'][0] == 0) { echo '上传了单个文件<br>'; echo move_uploaded_file($_FILES['upload_file']['tmp_name'][0], "./uploade/{$_FILES['upload_file']['name'][0]}") ? '单文件上传成功<br>' : '单文件上传失败<br>'; } else { echo '文件上传失败<br>'; } } else { echo '文件上传不符合规则<br>'; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>文件上传</title> </head> <body> <fieldset> <legend> 文件上传 </legend> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="upload_file[]" accept="image/*" multiple> <button>提交</button> </form> </fieldset> </body> </html>
点击 "运行实例" 按钮查看在线实例