Cml\Vendor\UploadFile::upload PHP Метод

upload() публичный Метод

上传所有文件
public upload ( null | string $savePath = null ) : boolean
$savePath null | string 上传文件的保存路径
Результат boolean
    public function upload($savePath = null)
    {
        is_null($savePath) && ($savePath = $this->config['savePath']);
        $savePath = $savePath . '/';
        $fileInfo = [];
        $isUpload = false;
        //获取上传的文件信息
        $files = $this->workingFiles($_FILES);
        foreach ($files as $key => $file) {
            //过滤无效的选框
            if (!empty($file['name'])) {
                //登记上传文件的扩展信息
                !isset($file['key']) && ($file['key'] = $key);
                $pathinfo = pathinfo($file['name']);
                $file['extension'] = $pathinfo['extension'];
                $file['savepath'] = $savePath;
                $saveName = $this->getSaveName($savePath, $file);
                $file['savename'] = $saveName;
                //取得文件名
                //创建目录
                if (is_dir($file['savepath'])) {
                    if (!is_writable($file['savepath'])) {
                        $this->errorInfo = "上传目录{$savePath}不可写";
                        return false;
                    }
                } else {
                    if (!mkdir($file['savepath'], 0700, true)) {
                        $this->errorInfo = "上传目录{$savePath}不可写";
                        return false;
                    }
                }
                //自动查检附件
                if (!$this->secureCheck($file)) {
                    return false;
                }
                //保存上传文件
                if (!$this->save($file)) {
                    return false;
                }
                unset($file['tmp_name'], $file['error']);
                $fileInfo[] = $file;
                $isUpload = true;
            }
        }
        if ($isUpload) {
            $this->successInfo = $fileInfo;
            return true;
        } else {
            $this->errorInfo = '没有选择上传文件';
            return false;
        }
    }