PHP code example of originphp / storage

1. Go to this page and download the library: Download originphp/storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

originphp / storage example snippets


use Origin\Storage\Storage;
use Origin\Storage\Engine\LocalEngine;

Storage::config('default', [
    'className' => LocalEngine::class
    'root' => '/var/www/storage'
]);

use Origin\Storage\Storage;
Storage::write('test.txt','hello world!');

Storage::write('my_folder/test.txt','hello world!');

use Origin\Storage\Storage;
$contents = Storage::read('my_folder/test.txt');

Storage::delete('my_folder/test.txt');
Storage::delete('my_folder');

use Origin\Storage\Storage;
$allFiles = Storage::list();

// Will look like this
Origin\Storage\FileObject Object
(
    [name] => bar.txt
    [directory] => folder
    [path] => folder/bar.txt
    [extension] => txt
    [timestamp] => 1601121922
    [size] => 32
)

echo $file->name;
echo $file['name'];

use Origin\Storage\Storage;
$files = Storage::list('my_folder');

$volume = Storage::volume('sftp-backup');
$data = $volume->read('transactions.csv');

$data = Storage::read('transactions.csv',[
    'config'=>'sftp-backup'
]);

use Origin\Storage\Storage;
use Origin\Storage\Engine\LocalEngine;

Storage::config('default', [
    'className' => LocalEngine::class
    'root' => '/var/www/storage',
    'lock' => true // default
 ]);

use Origin\Storage\Storage;
use Origin\Storage\Engine\FtpEngine;

Storage::config('default', [
    'className' => FtpEngine::class
    'engine' => 'Ftp',
    'host' => 'example.com',
    'port' => 21,
    'username' => 'james',
    'password' => 'secret',
    'ssl' => false
 ]);

use Origin\Storage\Storage;
use Origin\Storage\Engine\SftpEngine;

Storage::config('default', [
    'className' => SftpEngine::class
    'host' => 'example.com',
    'port' => 22,
    'username' => 'james',
    'password' => 'secret'
 ]);

use Origin\Storage\Storage;
use Origin\Storage\Engine\SftpEngine;

Storage::config('default', [
    'className' => SftpEngine::class
    'host' => 'example.com',
    'port' => 22,
    'username' => 'james',
    'privateKey' => '/var/www/config/id_rsa'
]);

use Origin\Storage\Storage;
use Origin\Storage\Engine\S3Engine;

Storage::config('default', [
    'className' => S3Engine::class
    'credentials' => [
        'key' => env('S3_KEY'), // * protocols
    'bucket' => env('S3_BUCKET') // * 

use Origin\Storage\Storage;
use Origin\Storage\Engine\ZipEngine;

Storage::config('default', [
    'className' => ZipEngine::class
    'file' => '/var/www/backup.zip'
]);
linux
$ composer