PHP code example of jovialcore / cake-cloudinary

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

    

jovialcore / cake-cloudinary example snippets


// config/app_local.php
// In the return block, add: 

    // ...
    'Cloudinary' => [
        'default' => [
            'cloud_name' => 'your_cloud_name',
            'api_key' => 'your_api_key',
            'api_secret' => 'your_api_secret',
            'secure' => true // use HTTPS
        ],
    ],
    // ...
];

// src/Controller/YourController.php

namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Event\EventInterface;

class YourController extends Controller
{
    public function initialize(): void
    {
        parent::initialize();
        $this->loadComponent('CakeCloudinary.Cloudinary');
    }

    // ...
}

$this->Cloudinary->upload($file, ['getUrl' => 'true']);

$this->Cloudinary->uploadVideo($file, ['getUrl' => 'true']);

$this->Cloudinary->uploadFile($file, ['getUrl' => 'true']);

$this->Cloudinary->upload($file,[
    'folder' => 'my_cloudinary_folder',
      'public_id' => 'my_video_name',
]);

$url = $this->Cloudinary->getUrl(); // get url of uploaded file (http)

$secureUrl = $this->Cloudinary->getSecureUrl(); //  get secureUrl of the uploaded asst

$publicId = $this->Cloudinary->getPublicId(); // get public Id of the uploaded asset

$originalFIleName = $this->Cloudinary->getOriginalFileName(); // get the asset name before it was uploaded to cloudinary

$resourceType = $this->Cloudinary->getUploadedAt(); // get the time the asset as uploaded

$extension = $this->Cloudinary->getExtension(); // get file extension of the uploaded asset e.g jpg, .pdf, .png, etc

$fileType = $this->Cloudinary->getFileType(); // get asset type. E.g, image, video, etc. 

$fileSize = $this->Cloudinary->getFileSize(); //get uploaded asset file's size by defaults, it returns a human readable file size like 20MB, 20kb, etc

// If you prefer to get just the raw bytes, 
$fileizeInBytes = this->Cloudinary->getFileSize(['human_readable' => false]);


$height = $this->Cloudinary->getHeight(); // get asset height

$width = $this->Cloudinary->getWidth(); // get asset width

$res = $this->Cloudinary->delete($publidId);

// get url from an asset

$url = $this->Cloudinary->fetchUrl($publicId);