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

Commit

Permalink
Added ability to download a file from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmyers committed May 6, 2014
1 parent f0b130f commit 3d6dc73
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Dmyers/Storage/Adapter/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Dmyers/Storage/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Dmyers/Storage/Adapter/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down

0 comments on commit 3d6dc73

Please sign in to comment.