LocalUpload.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Modules\Common\Support\Upload\Uses;
  3. use Illuminate\Support\Facades\Storage;
  4. class LocalUpload extends Upload
  5. {
  6. /**
  7. * upload
  8. *
  9. * @return array
  10. */
  11. public function upload(): array
  12. {
  13. return $this->addUrl($this->getUploadPath());
  14. }
  15. /**
  16. * app url
  17. *
  18. * @param $path
  19. * @return mixed
  20. */
  21. protected function addUrl($path): mixed
  22. {
  23. $path['path'] = config('app.url') . '/'. $path['path'];
  24. return $path;
  25. }
  26. /**
  27. * local upload
  28. *
  29. * @return string
  30. */
  31. protected function localUpload(): string
  32. {
  33. $this->checkSize();
  34. $storePath = 'uploads' . DIRECTORY_SEPARATOR . $this->getUploadedFileMimeType() . DIRECTORY_SEPARATOR . date('Y-m-d', time());
  35. $filename = $this->generateImageName($this->getUploadedFileExt());
  36. Storage::build([
  37. 'driver' => 'local',
  38. 'root' => $storePath
  39. ])->put($filename, $this->file->getContent());
  40. return $storePath . DIRECTORY_SEPARATOR . $filename;
  41. }
  42. }