Laravel uses Frank de Jonge PHP Package For managing Filesystem. Laravel provides simple drivers to manage local filesystem, Amazon S3, and Rackspace Cloud Storage. You can easily switch between these filesystems with no change in API's.
Laravel makes Filesystem configuration is an easy task, the configuration of the filesystem is located at config/filesystems.php. Within this file, you can configure your all disks local or remote. Each disk represents a particular storage driver and storage location.
In Laravel by Default, Filesystem Disk is set to local. to Read, Write and Delete a file from the local filesystem in Laravel5 you need to make any changes in config/filesystems.php.
When you are using the local driver, all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt:
In order to read a file from local disk Storage::get() method is used. get method takes the name of the file and returns its content. Below is sample usage.
$contents = Storage::get('file.jpg');
use IlluminateSupportFacadesStorage; $url = Storage::url('file1.jpg');
Storage::copy('old/file1.jpg', 'new/file1.jpg'); Storage::move('old/file1.jpg', 'new/file1.jpg');
$path = $request->file('avatar')->store('avatars');
The delete method is used for Deleting or removing a file from Disk. Delete method accepts a single filename or an array of files to remove from the disk. Below is the usage guide.
use IlluminateSupportFacadesStorage; Storage::delete('file.jpg');
This post is submitted by one of our members. You may submit a new post here.
Laravel interview Questions © 2019 - Designed by PSD to HTML