PHP code example of xinningsu / flysystem-baidu-bos

1. Go to this page and download the library: Download xinningsu/flysystem-baidu-bos 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/ */

    

xinningsu / flysystem-baidu-bos example snippets




// Instantiate
$client = new \Sulao\BaiduBos\Client([
    'access_key' => 'access key',
    'secret_key' => 'secret key',
    'bucket' => 'bucket',
    'region' => 'region',
    'options' => ['connect_timeout' => 10] // Optional, guzzle request options
]);
$adapter = new \Sulao\Flysystem\BaiduBos\BaiduBosAdapter($client);
$filesystem = new \League\Flysystem\Filesystem($adapter, ['disable_asserts' => true]);

// Write a new file.
$filesystem->write('file.txt', 'contents');

// Write a new file using a stream.
$filesystem->writeStream('file.txt', fopen('/resource.txt', 'r'));

// Create a file or update if exists.
$filesystem->put('file.txt', 'contents');

// Create a file or update if exists using a stream.
$filesystem->putStream('file.txt', fopen('/resource.txt', 'r'));

// Update an existing file.
$filesystem->update('file.txt', 'contents');

// Update an existing file using a stream.
$filesystem->updateStream('file.txt', fopen('/resource.txt', 'r'));

// Read a file.
$content = $filesystem->read('file.txt');

// Retrieves a read-stream for a path.
$stream = $filesystem->readStream('file.txt');

// Check whether a file exists.
$has = $filesystem->has('file.txt');

// Copy a file.
$filesystem->copy('file.txt', 'file2.txt');

// Rename a file.
$filesystem->rename('file.txt', 'file2.txt');

// Delete a file.
$filesystem->delete('file.txt');

// Get a file's metadata.
$meta = $filesystem->getMetadata('file.txt');

// Get a file's size.
$size = $filesystem->getSize('file.txt');

// Get a file's mime-type.
$mimeType = $filesystem->getMimetype('file.txt');

// Get a file's timestamp.
$ts = $filesystem->getTimestamp('file.txt');

// Set the visibility for a file.
$filesystem->setVisibility('file.txt', 'public');

// Get a file's visibility.
$visibility = $filesystem->getVisibility('file.txt');

// Delete a directory.
$filesystem->deleteDir('test/');

// Create a directory.
$filesystem->createDir('test/');

// List contents of a directory.
$lists = $filesystem->listContents('test/', true);