PHP code example of black-bits / bestcdn-sdk-php

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

    

black-bits / bestcdn-sdk-php example snippets


$key     = "myPath/myFileName.ext";      // desired path on cdn
$file    = __DIR__ . "/file.ext";        // local absolute path
$respose = BestCdn::putFile($key, $file); 

class FileController extends Controller
{
    public function putFile(Request $request, BestCdn $cdn)
    {
        // ...
        $key     = "myPath/myFileName.ext"; // desired path on cdn
        $file    = __DIR__ . "/file.ext";   // local absolute path
        $respose = $cdn->putFile($key, $file); 
        // ...
    }
}

$config = [

    'connections' => [
        'default' => [
            "credentials" => [
                "key"    => "YourBestCdnProjectKey",    // i" => "https://management.bestcdn.io/", // defaultConnection" => "default", // optional, if you configure multiple connections (multiple projects/testing/production)
];

$cdn     = new BestCdn($config);
$key     = "myPath/myFileName.ext"; // desired path on cdn
$file    = __DIR__ . "/file.ext";   // local absolute path
$respose = $cdn->putFile($key, $file);

$key     = "myPath/myFileName.md"; // desired path on cdn
$file    = __DIR__ . "/README.md"; // local absolute path
$respose = $cdn->putFile($key, $file);

$key     = "myPath/myFileName.jpeg";                                           // desired path on cdn
$uri     = "https://static.pexels.com/photos/460797/pexels-photo-460797.jpeg"; // public uri
$respose = $cdn->putFileByUri($key, $uri);

var_dump($response->data());

$response['cdn_link'];
$response->get('cdn_link');

$cdn = new BestCdn($config);

$key  = "myPath/myFileName.md";
$file = __DIR__ . "/README.md";

$result = $cdn->putFile($key, $file);
if ( $result->hasError() ) {
    print $result->statusCode();
    print $result->message();
    // ... abort mission!
}

// ... normal code

composer 

php artisan vendor:publish --provider="BlackBits\BestCdn\BestCdnServiceProvider"