60 lines
1.2 KiB
PHP
Raw Normal View History

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-08 15:38:06 +08:00
if (Str::of($path['path'])->contains('\\')) {
$path['path'] = Str::of($path['path'])->replace('\\', '/');
}
2023-01-11 17:17:36 +08:00
$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;
}
}