false, 'checkExtensionByMimeType' => false], //这规则奇怪的放走近科学都可以拍好几集了 ]; } public function upload(): bool { if ($this->validate()) { if ($this->targetDir === null) { $this->targetDir = '.'; } if (str_contains($this->targetDir, '..')) { return false; } $userHomeDir = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . Yii::$app->user->id; $absolutePath = $userHomeDir . '/' . $this->targetDir; if (!is_dir($absolutePath)) { return false; } $fileName = $this->uploadFile->fullPath; $directory = dirname($absolutePath . '/' . $fileName); if (!is_dir($directory)) { mkdir($directory, 0777, true); } if (!FileSizeHelper::hasEnoughSpace($this->uploadFile->size)) { return false; } $this->uploadFile->saveAs($absolutePath . '/' . $fileName); return true; } else { return false; } } }