PHP code example of knight / ucloud

1. Go to this page and download the library: Download knight/ucloud 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/ */

    

knight / ucloud example snippets


'providers' => [
    // Other service providers...
    Knight\Ucloud\UcloudServiceProvider::class,
],
'aliases' => [
    // Other aliases...
    'Ucloud' => \Knight\Ucloud\Ucloud::class,
],


'disks' => [
    //other...
       
    'ucloud'=>[
        'suffix'=>env('UCLOUD_PROXY_SUFFIX',''),
        'public_key'=>env('UCLOUD_PUBLIC_KEY',''),
        'private_key'=>env('UCLOUD_PRIVATE_KEY',''),
    ]

],
$xslt

use Knight\Ucloud\Ucloud;

class IndexController
{

    public function index(){

        $bucket = "bucket";
        //上传至存储空间后的文件名称(请不要和API公私钥混淆)
        $key    = "your name ";
        //待上传文件的本地路径
        $file   = "/Users/knight/Desktop/picture.png";
        list($data, $err) = Ucloud::UCloud_PutFile($bucket, $key, $file);
        if ($err) {
            echo "error: " . $err->ErrMsg . "\n";
            echo "code: " . $err->Code . "\n";
            exit;
        }
        echo "ETag: " . $data['ETag'] . "\n";

    }

}