_path = $path; } final public function getPath(): string { return $this->_path; } public function getFileEntity(): 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(); if (!is_dir($fullPath)) { if (!mkdir($fullPath)) { throw new \Exception("디렉토리 생성 실패:{$fullPath}"); } } $saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName; if (file_exists($saveFilePath)) { throw new \Exception("이미 존재하는 파일:{$saveFilePath}"); } if (!file_put_contents($saveFilePath, $content)) { throw new \Exception("파일저장 실패:{$saveFilePath}"); } $entity = $this->getFileEntity(); $entity->setPath($this->getPath()); $entity->setTitle($fileName); $entity->setMimeType(mime_content_type($saveFilePath)); $entity->setSize(!filesize($saveFilePath) ?: 0); $entity->setSequence($file_sequence); $entity->setMediaHTML($this->getMediaTag($mediaType, $entity)); log_message("debug", "{$file_sequence}번째 " . $entity->getTitle() . " 파일저장 완료"); return $entity; } }