定制 jovialcore/cake-cloudinary 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jovialcore/cake-cloudinary

最新稳定版本:v1.0.0

Composer 安装命令:

composer require jovialcore/cake-cloudinary

包简介

CakeCloudinary plugin for CakePHP

README 文档

README

The CakePHP Cloudinary Plugin provides an easy-to-use wrapper for the Cloudinary PHP SDK to enable easy file uploads to your Cloudinary account in CakePHP projects.

Install the plugin using composer

Installation

composer require jovialcore/cake-cloudinary

You will also need to configure the Cloudinary credentials in the app.php file:

// 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
        ],
    ],
    // ...
];

Usage

To use the Cloudinary component in your controller, you need to load it in your initialize method:

// 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');
    }

    // ...
}

Uploading an asset

The $file parameter can be a file path, a File object or a $this->request->getUploadedFiles() | $this->request->getUploadedFile(); object.

Quickily upload an asset and return a secure url

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

Quickily upload a video asset and return a secure url

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

Quickily upload any file (e.g, pdf, csv, etc) asset and return a secure url

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

The assets method can also take an array of options as second argument. The options array can include any of the options supported by the Cloudinary API. See the Cloudinary PHP Image Upload API documentation for a list of available options. Example:

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

The asset method/apis also returns a response object that contains the uploaded image's metadata, including its URL and public ID. You can retrieve the URL of the uploaded image using the getUrl or getSecureUrl methods of the Cloudinary component:

$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

Delete assets

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

Fetching remote assets

// get url from an asset

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

Credits

This plugin drew inspiration from the Laravel Cloudinary Package

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固