Atom Framework
Go to Github
v1.0.0
v1.0.0
  • Installation
  • Getting Started
  • Configuration
    • Environment
    • Authentication
  • Basics
    • Routing
    • Middleware
    • Controllers
    • Models
    • Requests
    • Views
    • URL Generation
    • Session
  • Misc
    • Security
      • Encryption
      • Hashing
    • Storage
    • Moment
Propulsé par GitBook

© 2025 Licon Corp

Sur cette page
  • The Public Disk
  • The Local Disk
  • Obtaining Disk Instances
  • Retrieving Files
  • File URLs
  • Storing Files
  • Deleting Files
  • Get All Files Within A Directory

Cet article vous a-t-il été utile ?

  1. Misc

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:

echo asset('storage/file.txt');

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:

$storage = new Atom\Storage\Storage('local');

$storage->put('file.txt', 'Contents');

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:

use Atom\Atom\Storage;

$storage = new Storage('public');
$local_storage = new Storage();

$storage->put('avatar.png', $fileContents');
$local_storage->put('file.txt', 'Contents');

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:

$storage = new Storage('public');

$contents = $storage->get('file.jpg');

The exists method may be used to determine if a file exists on the disk:

$exists = $storage->exists('file.jpg');

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:

$storage = new Storage('public');

$url = $storage->path('file.jpg');

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:

use Atom\Storage\Storage;

$storage = new Storage('local');

$storage->put('file.txt', 'Simple text contents');

$storage->put('file.bin', $resource, true);

Deleting Files

The delete method accepts a single filename to remove from the disk:

$storage->delete('file.txt');

Get All Files Within A Directory

The getFiles method returns an array of all of the files in the storage disk:

$storage = new Storage('public');

$files = $storage->files();
PrécédentHashingSuivantMoment

Dernière mise à jour il y a 6 ans

Cet article vous a-t-il été utile ?