[PHP文件上传下载]⑤--多文件上传

[PHP文件上传下载]⑤--多文件上传_第1张图片
Paste_Image.png

test.php




请选择您要上传的文件:
请选择您要上传的文件:
请选择您要上传的文件:
请选择您要上传的文件:

common.func.php

upload.func.php

 $val) {
                $files[$i]['name'] = $file['name'][$key];
                $files[$i]['type'] = $file['type'][$key];
                $files[$i]['tmp_name'] = $file['tmp_name'][$key];
                $files[$i]['error'] = $file['error'][$key];
                $files[$i]['size'] = $file['size'][$key];
                $i++;
            }
        }
    }
    return $files;
}

function uploadFile($fileInfo, $path = './uploads', $flag = true,
                    $maxSize = 1048576, $allowExt = array('jpeg', 'jpg', 'gif', 'png'))
{
    $res = null;
    //判断错误号
    if ($fileInfo['error'] === UPLOAD_ERR_OK) {
        if ($fileInfo['size'] > $maxSize) {
            $res['mes'] = $fileInfo['name'] . '上传文件过大';
        }
        $ext = getExt($fileInfo['name']);
        if (!in_array($ext, $allowExt)) {
            $res['mes'] = $fileInfo['name'] . '非法文件类型';
        }
        if ($flag && !$res['mes']) {
            if (!getimagesize($fileInfo['tmp_name'])) {
                $res['mes'] = $fileInfo['name'] . "不是真实图片类型";
            }
        }
        if (!is_uploaded_file($fileInfo['tmp_name'])) {
            $res['mes'] = $fileInfo['name'] . "文件不是通过HTTP POST方式上传来的";
        }
        if ($res['mes']) {
            return $res['mes'];
        }
        if (!file_exists($path)) {
            mkdir($path, 0777, true);
            chmod($path, 0777);
        }
        $uniName = getUniName();
        $destination = $path . '/' . $uniName . '.' . $ext;
        if (move_uploaded_file($fileInfo['tmp_name'], $destination)) {
            $res['mes'] = $fileInfo['name'] . "文件移动失败";
        }
        $res['mes'] = $fileInfo['name'] . '上传成功';
        $res['dest'] = $destination;
        return $res;


    } else {
        switch ($fileInfo['error']) {
            case 1:
                $res['mes'] = "上传文件超过了PHP配置文件中upload_max_file";
                break;
            case 2:
                $res['mes'] = "超过了表单MAX_FILE_SIZE";
                break;
            case 3:
                $res['mes'] = "文件部分被上传";
                break;
            case 4:
                $res['mes'] = "没有选择上传文件";
                break;
            case 6:
                $res['mes'] = "没有找到临时目录";
                break;
            case 7:
            case 8:
                $res['mes'] = "系统错误";
                break;
        }
        return $res['mes'];
    }
}

doAction.php

";
    $uploadFiles[] = $res['dest'];
}
$uploadFiles = array_values(array_filter($uploadFiles));
var_dump($uploadFiles);
?>
[PHP文件上传下载]⑤--多文件上传_第2张图片
Paste_Image.png
[PHP文件上传下载]⑤--多文件上传_第3张图片
Paste_Image.png

你可能感兴趣的:([PHP文件上传下载]⑤--多文件上传)