K7

K7Blog

须知少年凌云志 曾许人间第一流.
proton
telegram

PHP uses cloudflare r2 to store uploaded files

Recently, I've been tinkering with cloudflare's r2 storage and also activated the chatgpt plus version, allowing chatgpt to write such an upload function.

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

Tutorial:#

You need to customize lines 7-11 and 29 in 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 to everyone below!

Open cloudflare r2 storage - Add a management R2API token

Snipaste_2023-03-19_03-32-07

Pay attention to selecting the permission that can be edited.

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

$bucket = Bucket name!

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

The twenty-ninth line is the API of the bucket

Snipaste_2023-03-19_03-36-47

Note that the bucket name will be added after this link, just remove this name.

The uploaded files will be sorted by date, then the file name will be renamed and the complete link will be returned.

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

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