This package allows you to store files on any place, even local filesystem, or cloud CDN, FTP servers etc.
To accomplish this, a common way to describe a file location is needed.
Let's assume that you have a file stored on
We can tell about this file that it:
- has the
- has the
So, finally, we can describe it as
In conclusion, any file is always stored in a location that matches the following pattern of URI:
For example if we store a file in openstack onbject storage we can have the following uri for it:
app/config/app.php and add the following lines
'aliases' => ... 'Storage' => 'Softservlet\FileManager\StorageFacade' 'providers' => ... 'Softservlet\FileManager\FileManagerServiceProvider'
Firstly we will instantiate a new
FileInterface implementation object, which accpets as parameter the URI of the FileInterface.
By default, if the URI doesn not conaint a schema then the file:// schema will be interpreted
use Softservlet\FileManager\File\GenericFile; //See Softservlet\FileManager\File\FileInterface $file = new GenericFile('/home/user/image.jpg');
We will call then the
StorageFactory class to store the file (for this Storage facade is used here).
store method accepts as parameter an FileInterface and optionally an
If the StorageInterface is not given, the file will be stored using the FilesystemStorage Driver.
$uri = Storage::store($file);
If you have an openstack storage implementation you will can call
$uri = Storage::store($file, new OpenstackStorage)
We stored a file, now we want to retrieve it from the storage mechanism.
For this, we will use the
fileDescriptor() method declared on
StorageInterface, and wich is implemented by each storage driver.
It accepts as parameter an
FileInterface and return an
//we stored the file and got the $uri variable $file = new GenericFile($uri); $descriptor = Storage::fileDescriptor($file); //See Softservlet\FileManager\File\FileDescriptorInterface $contents = $descriptor->contents(); $mime = $descriptor->mime();
To get an http url for accessing a file, you may use an implementation of
Until now, there is an implementation for file stored with
use Softservlet\FileManager\Deliver\LocalHttpDelivery; $file = new GenericFile($uri); $delivery = new LocalHttpDelivery(); $url = $delivery->httpUrl($file);