PHP code example of houxiaobei / qcloud-cos-v4

1. Go to this page and download the library: Download houxiaobei/qcloud-cos-v4 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/ */

    

houxiaobei / qcloud-cos-v4 example snippets


$config = array(
    'app_id' => '',
    'secret_id' => '',
    'secret_key' => '',
    'region' => 'gz',
    'timeout' => 60
);

// 包含cos-php-sdk-v4/include.php文件
 'app_id' => '',
    'secret_id' => '',
    'secret_key' => '',
    'region' => 'gz',
    'timeout' => 60
);
$cosApi = new Api($config);

// 创建文件夹
$ret = $cosApi->createFolder($bucket, $folder);
var_dump($ret);

// 上传文件
$ret = $cosApi->upload($bucket, $src, $dst);
var_dump($ret);

// 下载文件
$ret = $cosApi->download($bucket, $src, $dst);
var_dump($ret);

// 目录列表
$ret = $cosApi->listFolder($bucket, $folder);
var_dump($ret);

// 更新目录信息
$bizAttr = "";
$ret = $cosApi->updateFolder($bucket, $folder, $bizAttr);
var_dump($ret);

// 更新文件信息
$bizAttr = '';
$authority = 'eWPrivateRPublic';
$customerHeaders = array(
    'Cache-Control' => 'no',
    'Content-Type' => 'application/pdf',
    'Content-Language' => 'ch',
);
$ret = $cosApi->update($bucket, $dst, $bizAttr, $authority, $customerHeaders);
var_dump($ret);

// 查询目录信息
$ret = $cosApi->statFolder($bucket, $folder);
var_dump($ret);

// 查询文件信息
$ret = $cosApi->stat($bucket, $dst);
var_dump($ret);

// 删除文件
$ret = $cosApi->delFile($bucket, $dst);
var_dump($ret);

// 删除目录
$ret = $cosApi->delFolder($bucket, $folder);
var_dump($ret);

// 复制文件
$ret = $cosApi->copyFile($bucket, '/111.txt', '/111_2.txt');
var_dump($ret);

// 移动文件
$ret = $cosApi->moveFile($bucket, '/111.txt', '/111_3.txt');
var_dump($ret);