UploadFacadeRepository.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\Repositories\Eloquent;
  3. use App\Repositories\Eloquent\BaseRepository;
  4. use App\Repositories\Contracts\UploadInterface;
  5. use Illuminate\Support\Facades\Storage;
  6. /**
  7. *
  8. * @author lilin
  9. *
  10. */
  11. class UploadFacadeRepository extends BaseRepository implements UploadInterface
  12. {
  13. public function pic($file, $dst = 'pics')
  14. {
  15. $this->setLog(self::TYPENAME. '图片开始', $this->startTime());
  16. $picInfo = getimagesize($file);
  17. if (! $picInfo) {
  18. $this->error()->notImageFile();
  19. }
  20. $srcPath = $file->getPathname();
  21. $extension = $file->getClientOriginalExtension();
  22. $fileName = time() . rand() . '.' . $extension;
  23. $dstPath = $dst . '/' . date('Y') . '/' . date('m');
  24. $size = $file->getSize();
  25. $path = Storage::putFile($dstPath, $file);
  26. $this->setLog(self::TYPENAME. '图片结束', $this->startTime, [$path]);
  27. return $this->response($path);
  28. }
  29. }