_path = $path;
}
final public function getPath(): string
{
return $this->_path;
}
public function getEntity(): FileEntity
{
if ($this->_entity === null) {
$this->_entity = new FileEntity();
$this->_entity->setPath($this->getPath());
}
return $this->_entity;
}
private function getMediaTag(string $mediaType): string
{
$mediaTag = "";
switch ($mediaType) {
case "image":
$mediaTag = sprintf(
"
",
$this->getUploadPath(),
$this->getEntity()->getPath(),
$this->getEntity()->getTitle(),
$this->getEntity()->getTitle()
);
break;
case "video":
$mediaTag = sprintf(
"",
$this->getEntity()->getTitle(),
$this->getUploadPath(),
$this->getEntity()->getPath(),
$this->getEntity()->getTitle(),
$this->getEntity()->getMimeType(),
);
break;
}
return $mediaTag;
}
public function save(string $fileName, string $mediaType, string $content, int $file_sequence)
{
$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 false;
}
$entity = $this->getEntity();
$entity->setTitle($fileName);
$entity->setMimeType(mime_content_type($saveFilePath));
$entity->setMediaHTML($this->getMediaTag($mediaType));
return $entity;
}
}