单文件上传

    function upload($file,$path='./upload',$size=10000000,array $type=array('image/jpeg','image/png','image/gif','image/jpg')){
        $file = $_FILES['albumPic'];
        $newName = '';
        //0.定义允许函数返回的信息
        $info = [];
        //1.判断错误号
        if($file['error'] > 0){
            switch($file['error']){
                case 1:
                    return '上传文件超过了PHP.INI配置文件中upload_max_filesize选项的值';
                case 2:
                    return '上传文件超过了HTML表单中设置的 FILE_MAX_SIZE的值';
                case 3:
                    return '只有部分文件被上传';
                case 4:
                    return '没有文件上传';
                case 6:
                    return '找不到临时目录';
                case 7:
                    return '文件写入失败';
            }
        }
posted @ 2022-02-28 12:01  unclesun  阅读(41)  评论(0)    收藏  举报