Skip to content

Commit d14ea13

Browse files
author
FreedomKnight
committed
新增 url method 並且修改文件
1 parent 90fde4a commit d14ea13

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ and it can add headers array by optional
6969

7070
return $entry->response($filename, ['Content-Disposition', 'attachement']);
7171

72+
### Parse File Path to URL
73+
if you store your file into cloud storage and you want to get url cloud site,
74+
you can use url() method to get it
75+
76+
$entry->url('wfjsdf.jpg'); // => "https://s3-ap-northeast-1.amazonaws.com/xxx/xxx/55c1e027caa62L.png"
77+
7278
### Work with Laravel Storage
7379

7480
* Get file content

src/FileEntry.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public function __construct($basepath = '/')
1515
$basepath .= '/';
1616
}
1717

18+
if (mb_substr($basepath, 0, 1, 'utf8') == '/') {
19+
$basepath = mb_substr($basepath, 1, null, 'utf8');
20+
}
21+
1822
$this->basepath = $basepath;
1923
}
2024

@@ -53,6 +57,18 @@ public function fullpath($filename)
5357
return $this->basepath . $filename;
5458
}
5559

60+
public function url($filename)
61+
{
62+
if (\Config::get('filesystems.default') == 's3') {
63+
return \Storage::getDriver()->getAdapter()->getClient()->getObjectUrl(
64+
\Storage::getDriver()->getAdapter()->getBucket(),
65+
$this->basepath . $filename
66+
);
67+
} else {
68+
return $this->basepath . $filename;
69+
}
70+
}
71+
5672
public function response($filename, $headers = [])
5773
{
5874
try {

0 commit comments

Comments
 (0)