定制 onurozdogan/cloudflare-image-api 二次开发

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

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

onurozdogan/cloudflare-image-api

最新稳定版本:0.0.4

Composer 安装命令:

composer require onurozdogan/cloudflare-image-api

包简介

Cloudflare Image API PHP Library

README 文档

README

This package is the code that I used in a single project and has been edited to make it usable in many projects. Since I need these functions in more than one project, I have prepared and presented them as a package.

Requirement

Laravel >= 9

Livewire >= 3

Php >= 8.0

Cloudflare Account

Installation

You can install the package via composer:

$ composer require onurozdogan/cloudflare-image-api

Usage

Configuration

First, you need to add the following configuration to your .env file.

CLOUDFLARE_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CLOUDFLARE_ACCOUNT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Upload Image

First parameter is image file, second parameter is image name.

$image = CloudflareImageApi::upload($request->file('image'), $name);

Response if image uploaded successfully:

if ($image->getStatusCode() == 200) {  // Check image uploaded successfully
    $img=$image->getData();            // Get image data 
    $db->image = $img->photoId;        // Save image id to database
}

Response if image uploaded failed:

if ($image->getStatusCode() != 200) {       // Check image uploaded failed
    $error=$image->getData();               // Get error message
    return response()->json($error, 400);   // Return error message (This is an example, you can use it as you wish)
}

Update Image

First parameter is image id (old image), second parameter is new image file, third parameter is image name

$image = CloudflareImageApi::update($db->image, $request->file('image'), $name);

Response if image updated successfully:

if ($image->getStatusCode() == 200) {  // Check image updated successfully
    $img=$image->getData();            // Get image data 
    $db->image = $img->photoId;        // Save image id to database
}

Response if image updated failed:

if ($image->getStatusCode() != 200) {       // Check image updated failed
    $error=$image->getData();               // Get error message
    return response()->json($error, 400);   // Return error message (This is an example, you can use it as you wish)
}

Delete Image

$image = CloudflareImageApi::delete($db->image);

Response if image deleted failed:

if ($image->getStatusCode() != 200) {       // Check image deleted failed
    $error=$image->getData();               // Get error message
    return response()->json($error, 400);   // Return error message (This is an example, you can use it as you wish)
}

Get Image In Blade

<img src="https://imagedelivery.net/your-account-hash/{{ $blog->image }}/public" alt="{{ $blog->title }}" loading="lazy">

Security

If you discover any security related issues, please contact me via https://onurozdogan.com. All security vulnerabilities will be fixed as soon as possible.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-10