Image & Video APIs

PHP quick start

Last updated: Jul-17-2025

This quick start lets you get an end-to-end implementation up and running using the PHP SDK in 5 minutes or less.

1. Set up and configure the SDK

Install the SDK

Use Composer to manage your PHP library dependency, and install Cloudinary's PHP library.

  1. Run the following command in the root folder of your project to add the SDK and update your composer.json:

    composer require cloudinary/cloudinary_php

  2. Install dependencies, including Cloudinary's PHP package, by running the following command:

    PHP
    composer install

    Note
    If you don't have the necessary permissions you can run the file itself: php composer.phar install.

Configure Cloudinary

Important
When writing your own applications, follow your organization's policy on storing secrets and don't expose your API secret.

In a new PHP file, php_quickstart.php, use your API environment variable to configure your Cloudinary credentials. Replace cloudinary://my_key:my_secret@my_cloud_name with your actual environment variable value:

php_quickstart.php
PHP
<html lang="HTML5">
<head>    <title>PHP Quick Start</title>  </head>
<body>
<?php

require __DIR__ . '/vendor/autoload.php';

// Use the Configuration class 
use Cloudinary\Configuration\Configuration;

// Configure an instance of your Cloudinary cloud
Configuration::instance('cloudinary://my_key:my_secret@my_cloud_name?secure=true');

2. Upload an image

Use the upload method of the UploadApi class to upload assets to Cloudinary. The code is encased in HTML to format and display the response:

php_quickstart.php (continued)
PHP
// Use the UploadApi class for uploading assets
use Cloudinary\Api\Upload\UploadApi;

// Upload the image
$upload = new UploadApi();

echo '******Upload response******';
echo '<br>';
echo '<pre>';
echo json_encode(
    $upload->upload('https://res.cloudinary.com/demo/image/upload/flower.jpg', [
        'public_id' => 'flower_sample',
        'use_filename' => true,
        'overwrite' => true]),
    JSON_PRETTY_PRINT
);
echo '</pre>';

3. Get info about the image

Use the asset method of the AdminApi class to return the details of our uploaded asset. The code is encased in HTML to format and display the response:

php_quickstart.php (continued)
PHP
// Use the AdminApi class for managing assets
use Cloudinary\Api\Admin\AdminApi;

// Get the asset details
$admin = new AdminApi();
echo '******Asset details******';
echo '<br>';
echo '<pre>';
echo json_encode($admin->asset('flower_sample', [
    'colors' => true]), JSON_PRETTY_PRINT
);
echo '</pre>';

4. Transform and deliver the image

Use the imageTag method to generate the full image URL based on the specified transformation parameters and add the image tag to your HTML code:

php_quickstart.php (continued)
PHP
// Use the Resize transformation group and the ImageTag class
use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\Background;
use Cloudinary\Tag\ImageTag;

// Create the image tag with the transformed image
$imgtag = (new ImageTag('flower_sample'))
    ->resize(Resize::pad()
        ->width(400)
        ->height(400)
        ->background(Background::predominant())
    );

echo '******Your transformed image******';
echo '<br>';
echo $imgtag;
// The code above generates an HTML image tag similar to the following:
//  <img src="https://res.cloudinary.com/demo/image/upload/b_auto:predominant,c_pad,h_400,w_400/flower_sample">

5. Run your code

Run your file by entering the following command in your terminal:

php php_quickstart.php

You’ll see console output for each step of the quick start. Click the generated URLs to view your uploaded image in the browser.

View the completed code

You can fork the sample code for this quick start from GitHub.

Next steps

  • Learn more about the PHP SDK by visiting the other pages in this SDK guide.
  • Get comprehensive details about Cloudinary features and capabilities:

✔️ Feedback sent!