Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Commit 3d6dc73

Browse files
committed
Added ability to download a file from storage
1 parent f0b130f commit 3d6dc73

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ Upload a file into storage:
6464
Storage::upload($_FILE['avatar'], 'user/avatar.jpg');
6565
```
6666

67+
Download a file from storage:
68+
69+
```php
70+
Storage::download('user/avatar.jpg', 'tmp/images/user-1/avatar.jpg');
71+
```
72+
6773
Delete a file from storage:
6874

6975
```php

src/Dmyers/Storage/Adapter/AmazonS3.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ public function upload($path, $target)
8080
));
8181
}
8282

83+
/**
84+
* {@inheritDoc}
85+
*/
86+
public function download($path, $target)
87+
{
88+
return $this->client->getObject(array(
89+
'Bucket' => $this->bucket,
90+
'Key' => $this->computePath($path),
91+
'SaveAs' => $target,
92+
));
93+
}
94+
8395
/**
8496
* {@inheritDoc}
8597
*/

src/Dmyers/Storage/Adapter/Base.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ abstract public function put($path, $contents);
6060
*/
6161
abstract public function upload($path, $target);
6262

63+
/**
64+
* Download a file from storage.
65+
*
66+
* @param string $path The path to the file to download.
67+
* @param string $target The path to the local file to store.
68+
*
69+
* @return bool
70+
*/
71+
abstract public function download($path, $target);
72+
6373
/**
6474
* Delete a file from storage.
6575
*

src/Dmyers/Storage/Adapter/Local.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public function upload($path, $target)
4545
return \File::move($path, $this->computePath($target));
4646
}
4747

48+
/**
49+
* {@inheritDoc}
50+
*/
51+
public function download($path, $target)
52+
{
53+
return \File::copy($this->computePath($target), $path);
54+
}
55+
4856
/**
4957
* {@inheritDoc}
5058
*/

0 commit comments

Comments
 (0)