_path = $path; } final public function getPath(): string { return $this->_path; } public function createFileEntity(): FileEntity { return new FileEntity(); } 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): FileEntity { $fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath(); $this->makeDirectory($fullPath); $saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName; if (file_exists($saveFilePath)) { throw new \Exception(__FUNCTION__ . "이미 존재하는 파일:{$saveFilePath}"); } if (!file_put_contents($saveFilePath, $content)) { throw new \Exception(__FUNCTION__ . "파일저장 실패:{$saveFilePath}"); } $entity = $this->createFileEntity(); $entity->setPath($this->getPath()); $entity->setTitle($fileName); $entity->setMimeType(mime_content_type($saveFilePath)); $entity->setSize(filesize($saveFilePath)); $entity->setSequence($file_sequence); $entity->setMediaHTML($this->getMediaTag($mediaType, $entity)); log_message("notice", __FUNCTION__ . " {$file_sequence}번째 " . $entity->getTitle() . " 작업 완료"); return $entity; } }