diff --git a/README.md b/README.md index d64da6f..97b6d1d 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,12 @@ Upload a file into storage: Storage::upload($_FILE['avatar'], 'user/avatar.jpg'); ``` +Download a file from storage: + +```php +Storage::download('user/avatar.jpg', 'tmp/images/user-1/avatar.jpg'); +``` + Delete a file from storage: ```php diff --git a/src/Dmyers/Storage/Adapter/AmazonS3.php b/src/Dmyers/Storage/Adapter/AmazonS3.php index da0b451..4ec96a9 100644 --- a/src/Dmyers/Storage/Adapter/AmazonS3.php +++ b/src/Dmyers/Storage/Adapter/AmazonS3.php @@ -80,6 +80,18 @@ public function upload($path, $target) )); } + /** + * {@inheritDoc} + */ + public function download($path, $target) + { + return $this->client->getObject(array( + 'Bucket' => $this->bucket, + 'Key' => $this->computePath($path), + 'SaveAs' => $target, + )); + } + /** * {@inheritDoc} */ diff --git a/src/Dmyers/Storage/Adapter/Base.php b/src/Dmyers/Storage/Adapter/Base.php index 763a21a..04bed45 100644 --- a/src/Dmyers/Storage/Adapter/Base.php +++ b/src/Dmyers/Storage/Adapter/Base.php @@ -60,6 +60,16 @@ abstract public function put($path, $contents); */ abstract public function upload($path, $target); + /** + * Download a file from storage. + * + * @param string $path The path to the file to download. + * @param string $target The path to the local file to store. + * + * @return bool + */ + abstract public function download($path, $target); + /** * Delete a file from storage. * diff --git a/src/Dmyers/Storage/Adapter/Local.php b/src/Dmyers/Storage/Adapter/Local.php index 754f1c0..8d3e0f0 100644 --- a/src/Dmyers/Storage/Adapter/Local.php +++ b/src/Dmyers/Storage/Adapter/Local.php @@ -45,6 +45,14 @@ public function upload($path, $target) return \File::move($path, $this->computePath($target)); } + /** + * {@inheritDoc} + */ + public function download($path, $target) + { + return \File::copy($this->computePath($target), $path); + } + /** * {@inheritDoc} */