49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MyStorage;
|
|
|
|
use App\Entities\MyStorage\FileEntity;
|
|
|
|
class FileLibrary extends MyStorageLibrary
|
|
{
|
|
private $_path = "";
|
|
protected $_entity = null;
|
|
public function __construct(string $path)
|
|
{
|
|
parent::__construct();
|
|
$this->_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;
|
|
}
|
|
|
|
public function save($content): null|FileEntity
|
|
{
|
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
|
if (!is_dir($fullPath)) {
|
|
if (!mkdir($fullPath)) {
|
|
throw new \Exception("Make Directory Error:" . $fullPath);
|
|
}
|
|
}
|
|
$entity = $this->getEntity();
|
|
$saveFile = $fullPath . DIRECTORY_SEPARATOR . $entity->getTitle();
|
|
log_message("debug", "Storage Save-> " . $saveFile);
|
|
if (!file_put_contents($saveFile, $content)) {
|
|
return null;
|
|
}
|
|
//File형식에 따른 MimeType 지정
|
|
$entity->setMimeType(mime_content_type($saveFile));
|
|
return $entity;
|
|
}
|
|
}
|