shitric / cloudflare-images
A simple PHP class for CloudFlare Images CDN
Installs: 1 131
Dependents: 0
Suggesters: 0
Security: 0
Stars: 21
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: >=7.2 || >=8.0
- ext-curl: *
- ext-json: *
README
A simple PHP class for CloudFlare Images CDN.
Dependencies
- PHP 7.3+
- cURL Library
Installation
With composer
composer require shitric/cloudflare-images
Manual
- Download the Images.php file from src
- Include your project with require or require_once functions. Choose what if you want.
Usage
Creating new instance.
You can get the construct parameters from your CloudFlare account.
$cloudFlareImages = new Images('Account_ID', 'API_Token', 'Images_Hash', 'Domain');
Image Uploading
I highly recommend using it with the try-catch block. Because this method throws Exception for cURL.
- 3rd parameter for delete image file after the uploading. Default value is
false
. - 4th parameter for metadata. Default value is
[]
. - 5th parameter for custom ID (max 1024 alpha-numeric chars). Default is
''
and lets Cloudflare generate the image ID. See Cloudflare Docs
Returns Image ID for getting the uploaded image from CDN
$imageId = $cloudFlareImages->uploadImageFile('File_Path', 'File_Name', false, ['key'=>'value'], 'Custom_ID');
Getting the Uploaded Image URL
Just give the Image ID and it will returns the direct Image url. Second parameter for image variant. Default is public.
$cloudFlareImages->getImageUrl('Image_ID', 'Variant');
Deleting the Image from CDN
Returns True or False.
$cloudFlareImages->deleteImage('Image_ID');