2023-01-11 17:17:36 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Common\Support\Upload\Uses;
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2023-05-08 15:38:06 +08:00
|
|
|
use Illuminate\Support\Str;
|
2023-01-11 17:17:36 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2023-05-10 16:53:22 +08:00
|
|
|
$path['path'] = config('app.url') . '/'.
|
2023-05-08 15:38:06 +08:00
|
|
|
|
2023-05-10 16:53:22 +08:00
|
|
|
Str::of($path['path'])->replace('\\', '/')->toString();
|
2023-01-11 17:17:36 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|