Using A Few Lines Of PHP to Programmatically Upload an Image To Cloudinary

I recently re-wrote  Ale House Rock using 11ty to generate the list and individual pages for beer and breweries.

I wanted to host the images on a CDN, specifically one that could process and optimise images. Sponsorship slots have worked as I immediately reached for  Cloudinary. Their  free tier was more than enough for my requirements so I set about integrating into my processes.

I was expecting to spend the whole evening on this requirement, however it seems Cloudinary has an absolute kick-ass  PHP SDK which, if you are using composer made it fairly straightforward to implement.

It helped that I already had a lot of the PHP structure in place. This article also assumes you are familiar with composer

Install the SDK

Installing the SDK with composer requires one command:

composer require cloudinary/cloudinary_php

Include the Classes

Add the following to the top of your PHP file

use Cloudinary\Configuration\Configuration;
use Cloudinary\Api\Upload\UploadApi;

#php

Using A Few Lines Of PHP to Programmatically Upload an Image To Cloudinary