feat: add uploader
This commit is contained in:
54
modules/Common/Support/Upload/Uses/LocalUpload.php
Normal file
54
modules/Common/Support/Upload/Uses/LocalUpload.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Common\Support\Upload\Uses;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class LocalUpload extends Upload
|
||||
{
|
||||
/**
|
||||
* upload
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function upload(): array
|
||||
{
|
||||
return $this->addUrl($this->getUploadPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* app url
|
||||
*
|
||||
* @param $path
|
||||
* @return mixed
|
||||
*/
|
||||
protected function addUrl($path): mixed
|
||||
{
|
||||
$path['path'] = config('app.url') . '/'. $path['path'];
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* local upload
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function localUpload(): string
|
||||
{
|
||||
$this->checkSize();
|
||||
|
||||
$storePath = 'uploads' . DIRECTORY_SEPARATOR . $this->getUploadedFileMimeType() . DIRECTORY_SEPARATOR . date('Y-m-d', time());
|
||||
|
||||
$filename = $this->generateImageName($this->getUploadedFileExt());
|
||||
|
||||
Storage::build([
|
||||
'driver' => 'local',
|
||||
'root' => $storePath
|
||||
])->put($filename, $this->file->getContent());
|
||||
|
||||
return $storePath . DIRECTORY_SEPARATOR . $filename;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user