A8

A8DOG

随便写写,记录折腾过程!
email
telegram

PHP uses cloudflare r2 to store uploaded files.

Recently, I have been working with Cloudflare's R2 storage and have also subscribed to the ChatGPT Plus version, which allows ChatGPT to write such an upload function.

Note: The vendor directory is installed using Composer for the AWS SDK for PHP.

Tutorial:#

You need to customize lines 7-11 and line 29 of the r2.php file.

$accessKey = 'your-access-key';
$secretKey = 'your-secret-key';
$region = 'your-region';
$bucket = 'your-bucket-name';
$customDomain = 'your-url';

'endpoint' => 'https://storage.googleapis.com',

Let me explain below!

Open Cloudflare R2 Storage - Add a Manage R2API Token

Snipaste_2023-03-19_03-32-07

Note that you can choose the permission to edit.

Fill in the short one with $accessKey and the long one with $secretKey!

$bucket = the name of the storage bucket!

$customDomain = the custom domain you added to the storage bucket!

The 29th line is the API for the storage bucket

Snipaste_2023-03-19_03-36-47

Note that this link will be followed by the name of your storage bucket, so remove this name.
The uploaded files will be sorted by date, and the file name will be renamed and the complete link will be returned.

File download link: https://r2.a8dog.com/2023/03/19/6416142e8364e.gz

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.