Skip to content

FileSystem_RemoteFile

StefansArya edited this page Apr 18, 2019 · 1 revision

You may need to assign the namespace to the top of your code

use \Scarlets\Library\FileSystem\RemoteFile;

The filesystem configuration are stored on /config/filesystem.php. Then you can pass {the storage name}/your/path to the LocalFile function.

In the configuration, the driver should be remotefile and the key is a secret code that must be similar for the remote server and the current server. The server must have storage key and the client must have host key.

For addional security, you may need to define array of allowed ip with allow-ip key.

Route and Listening incoming access (Remote Server)

It's important to define your secret route for this feature. So you will need this to be set somewhere in the /routes/.

route

The example below will occupy the URL of http://server.com/file-handler for transmission.

RemoteFile::route($url, $storage);

# Example
RemoteFile::route('/file-handler', 'incoming');

listen

Listen for incoming file access.
This can be used for blocking access, renaming file access (using reference parameter), or monitoring.

RemoteFile::listen($storage, $which, $callback);

# Example
RemoteFile::listen('incoming', 'put', function($path, &$value, $isFile){
    // ... Record to MySQL maybe?
});

Client Side

The usage RemoteFile library is pretty similar with LocalFile library.

For the example:

RemoteFile::put('{remote}/file.txt', 'my value');
$return = RemoteFile::contents('{remote}');

# Output: ['file.txt']
Clone this wiki locally