Automation/app/Libraries/MyStorage/FileLibrary.php
2024-09-07 19:00:11 +09:00

48 lines
1.2 KiB
PHP

<?php
namespace App\Libraries\MyStorage;
class FileLibrary extends MyStorageLibrary
{
private $_path = "";
private $_fileName = "";
private $_fileType = "";
public function __construct(string $path)
{
parent::__construct();
$this->_path = $path;
}
final public function getPath(): string
{
return $this->_path;
}
final public function getFileName(): string
{
return $this->_fileName;
}
final public function setFileName(string $fileName): void
{
$this->_fileName = $fileName;
}
final public function getFileType(): string
{
return $this->_fileType;
}
public function save($content): bool
{
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
if (!is_dir($fullPath)) {
if (!mkdir($fullPath)) {
throw new \Exception("Make Directory Error:" . $fullPath);
}
}
$saveFile = $fullPath . DIRECTORY_SEPARATOR . $this->getFileName();
$this->_fileType = $this->getFileMimeType($saveFile);
log_message("debug", "Storage Save-> " . $saveFile);
return file_put_contents($saveFile, $content);
}
}