29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Filesystem / Cloud Storage<br />

• Introduction<br />

• Configuration<br />

• Basic Usage A> - Obtaining Disk Instances A> - Retrieving Files A> - Storing Files A> - Deleting<br />

Files A> - Directories<br />

• Custom Filesystems<br />

Introduction<br />

Laravel provides a powerful filesystem abstraction thanks to the wonderful Flysystem¹⁵⁴ PHP<br />

package by Frank de Jonge. The Laravel Flysystem integration provides simple to use drivers<br />

for working with local filesystems, Amazon S3, and Rackspace Cloud Storage. Even better, it’s<br />

amazingly simple to switch between these storage options as the API remains the same for each<br />

system.<br />

Configuration<br />

The filesystem configuration file is located at config/filesystems.php. Within this file you may<br />

configure all of your “disks”. Each disk represents a particular storage driver and storage location.<br />

Example configurations for each supported driver is included in the configuration file. So, simply<br />

modify the configuration to reflect your storage preferences and credentials.<br />

Of course, you may configure as many disks as you like, and may even have multiple disks that use<br />

the same driver.<br />

The Local Driver<br />

When using the local driver, note that all file operations are relative to the root directory defined<br />

in your configuration file. By default, this value is set to the storage/app directory. Therefore, the<br />

following method would store a file in storage/app/file.txt:<br />

.<br />

1 Storage::disk('local')->put('file.txt', 'Contents');<br />

¹⁵⁴https://github.com/thephpleague/flysystem

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!