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

A simple filesystem abstraction package for Laravel 4.

License

Notifications You must be signed in to change notification settings

dmyers/laravel-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Storage Package for Laravel 4

Storage is a filesystem abstraction layer for Laravel 4 applications. If you are using Laravel 5 it comes with a similar package included which can be found in the docs.

Installation via Composer

Add this to you composer.json file, in the require object:

"dmyers/laravel-storage": "1.*"

After that, run composer install to install Storage.

Add the service provider to app/config/app.php, within the providers array.

'providers' => array(
    // ...
    'Dmyers\Storage\StorageServiceProvider',
)

Add a class alias to app/config/app.php, within the aliases array.

'aliases' => array(
    // ...
    'Storage' => 'Dmyers\Storage\Storage',
)

Finally, ensure the files directory defined in the config file is created and writable by the web server (defaults to public/files).

$ mkdir public/files
$ chmod -R 777 public/files

Configuration

Publish the default config file to your application so you can make modifications.

$ php artisan config:publish dmyers/laravel-storage

Usage

Check if a file exists in storage:

Storage::exists('user/avatar.jpg');

Get a file's contents from storage:

Storage::get('user/avatar.jpg');

Put a file into storage:

Storage::put('user/avatar.jpg', $contents);

Upload a file into storage:

Storage::upload(Input::file('avatar'), 'user/avatar.jpg');

Upload a remote file into storage:

Storage::remoteUpload('http://laravel.com/favicon.ico', 'user/avatar.jpg');

Download a file from storage:

Storage::download('user/avatar.jpg', 'tmp/images/user-1/avatar.jpg');

Download a remote file locally:

Storage::remoteDownload('http://laravel.com/favicon.ico', 'tmp/images/user-1/avatar.jpg');

Delete a file from storage:

Storage::delete('user/avatar.jpg');

Move a file in storage:

Storage::move('user/avatar.jpg', 'user/1/avatar.jpg');

Copy a file in storage:

Storage::copy('user/avatar.jpg', 'user/avatar.bak.jpg');

Get a file's type from storage:

Storage::type('user/avatar.jpg');

Get a file's mime type from storage:

Storage::mime('user/avatar.jpg');

Get a file's size from storage:

Storage::size('user/avatar.jpg');

Get a file's last modification date from storage:

Storage::lastModified('user/avatar.jpg');

Check if a path is a directory in storage:

Storage::isDirectory('user/avatar.jpg');

List all files in storage:

Storage::files('images');

Get the full URL to a file in storage:

Storage::url('user/avatar.jpg');

Render a file from storage to the browser:

Storage::render('user/avatar.jpg');