PHP code example of xinningsu / baidu-bos

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




// 实例化
$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
]);

// 添加或更新对象
$client->putObject('/object_name.txt', 'contents');

// 获取对象内容
$content = $client->getObject('/object_name.txt');

// 获取对象Meta信息
$meta = $client->getObjectMeta('/object_name.txt');

// 复制对象
$client->copyObject('/object_name.txt', '/new_object_name.txt');

// 追加数据
$client->appendObject('/object_name.txt', 'more contents');

// URL抓取资源
$client->fetchObject('/object_name.txt', 'https://www.baidu.com');

// 设置ACL
$client->putObjectAcl('/object_name.txt', 'public-read');

// 获取ACL
$acl = $client->getObjectAcl('/object_name.txt');

// 删除ACL
$client->deleteObjectAcl('/object_name.txt');

// 对象列表
$lists = $client->listObjects();

// 删除对象
$client->deleteObject('/object_name.txt');

// 批量删除对象
$client->deleteObjects(['/object_name.txt', '/object_name2.txt']);