_path = $path; } final public function getPath(): string { return $this->_path; } protected function getMediaTag(string $mediaType, FileEntity $entity): string { $mediaTag = ""; switch ($mediaType) { case "image": $mediaTag = sprintf( "\"%s\"", $this->getUploadPath(), $entity->getPath(), $entity->getTitle(), $entity->getTitle() ); break; case "video": $mediaTag = sprintf( "", $entity->getTitle(), $this->getUploadPath(), $entity->getPath(), $entity->getTitle(), $entity->getMimeType(), ); break; } return $mediaTag; } public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity { $fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath(); if (!is_dir($fullPath)) { if (!mkdir($fullPath)) { throw new \Exception("Make Directory Error:" . $fullPath); } } $saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName; log_message("debug", "Storage Save-> " . $saveFilePath); if (!file_put_contents($saveFilePath, $content)) { return null; } $entity = new FileEntity(); $entity->setPath($this->getPath()); $entity->setTitle($fileName); $entity->setMimeType(mime_content_type($saveFilePath)); $entity->setSize(filesize($saveFilePath)); $entity->setMediaHTML($this->getMediaTag($mediaType, $entity)); return $entity; } }