PHP code example of royfj / tencentyun-cos-php-sdk-v4

1. Go to this page and download the library: Download royfj/tencentyun-cos-php-sdk-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/ */

    

royfj / tencentyun-cos-php-sdk-v4 example snippets


// 包含cos-php-sdk-v4/include.php文件
的区域,对应关系如下:
//     华南  -> gz
//     华中  -> sh
//     华北  -> tj
Cosapi::setRegion('gz');

// 创建文件夹
$ret = Cosapi::createFolder($bucket, $folder);
var_dump($ret);

// 上传文件
$ret = Cosapi::upload($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);