Automation/app/Libraries/MyStorage/MyStorageFileLibrary.php
2024-09-05 20:13:31 +09:00

53 lines
1.3 KiB
PHP

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