tempName) if ($this->error == UPLOAD_ERR_OK) { $result = $this->driver->saveFile($this->tempName, $this->getFullPath($file)); } if ($result && $deleteTempFile) { $this->deleteTempFile(); } return $result; } /** * @param $baseName * @param bool $deleteTempFile * @return bool|string */ public function saveWithOriginalExtension($baseName, $deleteTempFile = true) { return $this->saveAs($baseName . '.' . $this->getExtension(), $deleteTempFile); } /** * @param $file * @return string */ protected function getFullPath($file) { return rtrim($this->basePath, '/') . '/' . ltrim($file, '/'); } /** * @return bool */ public function deleteTempFile() { return unlink($this->tempName); } /** * @param $name * @param $driver * @param $basePath * @return \yii\web\UploadedFile[] */ public static function getInstancesByStorage($name, $driver, $basePath) { parent::reset(); $instances = parent::getInstancesByName($name); foreach ($instances as $key => $instance) { if ($instance instanceof self) { $instance->driver = $driver; $instance->basePath = $basePath; continue; } unset($instances[$key]); } return $instances; } /** * @param $name * @param $driver * @param $basePath * @return mixed|\yii\web\UploadedFile|static|null */ public static function getInstanceByStorage($name, $driver, $basePath) { parent::reset(); $instance = parent::getInstanceByName($name); if ($instance instanceof self) { $instance->driver = $driver; $instance->basePath = $basePath; } return $instance; } }