Blogger Information
Blog 14
fans 1
comment 0
visits 4525
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示单文件上传与多文件上传和上传错误处理
叫我孙大树
Original
289 people have browsed it
<?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>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments