Storage
Atom provides a powerful filesystem abstraction. The Atom Filesystem integration provides simple to use drivers for working with local filesystems.
The Public Disk
The public
disk is intended for files that are going to be publicly accessible. By default, the public
disk uses the local
driver and stores these files in public/storage
.
Of course, once a file has been stored, you can create a URL to the files using the asset
helper:
The Local Disk
When using the local
driver, all file operations are relative to the storage/app
directory. Therefore, the following method would store a file in storage/app/file.txt
:
Obtaining Disk Instances
The Storage
class may be used to interact with any of your configured disks. For example, you may use the put
method on the class to store an avatar on the default disk. If you call methods on the Storage
class without defining the disk argument, the method call will automatically be passed to the local
disk:
Retrieving Files
The get
method may be used to retrieve the contents of a file. The raw string contents of the file will be returned by the method. Remember, all file paths should be specified relative to the "root" location of the disk:
The exists
method may be used to determine if a file exists on the disk:
File URLs
You may use the path
method to get the URL for the given file. If you are using the local driver, this will typically just prepend /storage to the given path and return a relative URL to the file:
Storing Files
The put
method may be used to store raw file contents on a disk. You may also pass a PHP resource
to the put
method. If you pass a PHP resource
as contents, you will need to set the serialize
argument to true. Serialize is greatly recommended when dealing with large files:
Deleting Files
The delete
method accepts a single filename to remove from the disk:
Get All Files Within A Directory
The getFiles
method returns an array of all of the files in the storage disk:
Dernière mise à jour
Cet article vous a-t-il été utile ?