Skip to content

Commit

Permalink
Filesystem 增加url方法 获取文件访问地址
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Nov 9, 2021
1 parent 03c2364 commit d3acc3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/think/filesystem/Driver.php
Expand Up @@ -17,6 +17,7 @@
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Memory as MemoryStore;
use League\Flysystem\Filesystem;
use RuntimeException;
use think\Cache;
use think\File;

Expand Down Expand Up @@ -91,6 +92,16 @@ public function path(string $path): string
return $path;
}

protected function concatPathToUrl($url, $path)
{
return rtrim($url, '/') . '/' . ltrim($path, '/');
}

public function url(string $path): string
{
throw new RuntimeException('This driver does not support retrieving URLs.');
}

/**
* 保存文件
* @param string $path 路径
Expand Down
8 changes: 8 additions & 0 deletions src/think/filesystem/driver/Local.php
Expand Up @@ -41,4 +41,12 @@ protected function createAdapter(): AdapterInterface
$permissions
);
}

public function url(string $path): string
{
if (isset($this->config['url'])) {
return $this->concatPathToUrl($this->config['url'], $path);
}
return parent::url($path);
}
}

0 comments on commit d3acc3e

Please sign in to comment.