Local.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace common\components\uploaddrive;
  3. use Yii;
  4. use common\helpers\RegularHelper;
  5. /**
  6. * Class Local
  7. * @package common\components\uploaddrive
  8. */
  9. class Local extends DriveInterface
  10. {
  11. /**
  12. * @param $baseInfo
  13. * @param $fullPath
  14. * @return mixed
  15. */
  16. protected function baseUrl($baseInfo, $fullPath)
  17. {
  18. $baseInfo['url'] = Yii::getAlias('@attachurl') . '/' . $baseInfo['url'];
  19. if ($fullPath == true && !RegularHelper::verify('url', $baseInfo['url'])) {
  20. $baseInfo['url'] = Yii::$app->request->hostInfo . $baseInfo['url'];
  21. }
  22. return $baseInfo;
  23. }
  24. /**
  25. * @param $baseInfo
  26. * @param $fullPath
  27. * @return mixed
  28. */
  29. protected function domainName($baseInfo, $fullPath)
  30. {
  31. $domain_name = Yii::getAlias('@attachurl') . '/';
  32. // if ($fullPath == true) $domain_name = Yii::$app->request->hostInfo;
  33. $baseInfo['domain_name'] = $domain_name;
  34. return $baseInfo;
  35. }
  36. /**
  37. * 初始化
  38. */
  39. protected function create()
  40. {
  41. // 判断是否追加
  42. if (isset($this->config['superaddition']) && $this->config['superaddition'] === true) {
  43. $this->adapter = new \League\Flysystem\Adapter\Local(Yii::getAlias('@attachment'), FILE_APPEND);
  44. } elseif (isset($this->config['alias_path'])) {
  45. $this->adapter = new \League\Flysystem\Adapter\Local($this->config['alias_path']);
  46. } else {
  47. $this->adapter = new \League\Flysystem\Adapter\Local(Yii::getAlias('@attachment'));
  48. }
  49. }
  50. }