PHP code example of benbjurstrom / cloudflare-images-php
1. Go to this page and download the library: Download benbjurstrom/cloudflare-images-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
benbjurstrom / cloudflare-images-php example snippets
use BenBjurstrom\CloudflareImages\CloudflareImages;
...
$api = new CloudflareImages(
apiToken: $_ENV['CLOUDFLARE_IMAGES_API_TOKEN'],
accountId: $_ENV['CLOUDFLARE_IMAGES_ACCOUNT_ID']
);
use Saloon\Laravel\Saloon; // composer ixture('getImage'),
]);
$id = 'a74a4313-a51d-4837-b5c1-73e4c562ff00';
// The initial request will check if a fixture called "getImage"
// exists. Because it doesn't exist yet, the real request will be
// sent and the response will be recorded to tests/Fixtures/Saloon/getImage.json.
$imgData = app(CloudflareImages::class)->images()->get($id);
// However, the next time the request is made, the fixture will
// exist, and Saloon will not make the request again.
$imgData = app(CloudflareImages::class)->images()->get();
use BenBjurstrom\CloudflareImages\Data\ImageData
...
$id = 'd63a6953-12b9-4d89-b8d6-083c86289b93'
/* @var ImageData $data */
$data = $api->images()
->private(false) // optional
->withMetadata(['user_id' => '123']) // optional
->update($id);
$data->id; // Contains a new id if the privacy setting was changed. If you are tracking IDs be sure to update your database.