Image & Video APIs

Upload images in PHP (video tutorial)

Last updated: Jul-17-2025

Overview

Learn how to upload images in PHP using the Cloudinary PHP SDK.

Video tutorial


Video Player is loading.
Current Time 0:00
Duration -:-
Loaded: 0%
Stream Type LIVE
Remaining Time 0:00
 
1x
  • Chapters
  • descriptions off, selected
  • captions off, selected

    This video is brought to you by Cloudinary's video player - embed your own!

    View the code
    You can find the code from this tutorial in GitHub.

    Tutorial contents

    This tutorial presents the following topics. Click a timestamp to jump to that part of the video.

    Introduction

    Jump to this spot in the video  0:00 In this tutorial, you'll learn how to upload one or more images to Cloudinary using the PHP SDK, a crucial part of your workflow for managing visual media.

    Upload a single image from your local file system

    Jump to this spot in the video  0:15 This tutorial assumes you've already installed and configured the PHP SDK.
    To begin uploading, import the necessary Cloudinary classes, create an instance of the UploadApi class, and call the upload method with the full path to your image. Here's a basic example using a file in your images/ folder:
    PHP
    use Dotenv\Dotenv;
    use Cloudinary\Cloudinary;
    use Cloudinary\Configuration\Configuration;
    use Cloudinary\Api\Upload\UploadApi;
    
    // Load .env file
    $dotenv = Dotenv::createImmutable(__DIR__);
    $dotenv->load();
    
    // Initialize Configuration
    $config = new Configuration($_ENV['CLOUDINARY_URL']);
    
    $cld = new Cloudinary($config);
    
    $upload = new UploadApi($config);
    
    // Upload the first image
    $response = $upload->upload('images/people-walking.jpg');

    Upload response

    Jump to this spot in the video  0:51 Once executed, the script will return a response object containing metadata and the delivery URL. You can use the secure_url to access the uploaded image:
    PHP
    echo $response['secure_url'];

    Upload multiple images from your local file system

    Jump to this spot in the video  1:12 To upload multiple images, loop through an array of file paths and upload each one individually. Only the secure_url is printed for simplicity. You can also view all uploaded images in the Media Library.
    PHP
    // Array of image paths
    $imagePaths = [
       'images/dress.jpg',
       'images/drinks.jpg',
       'images/fruit.jpg',
       'images/shoes.jpg'
    ];
    
    foreach ($imagePaths as $imagePath) {
       // Upload the image
       $response = $upload->upload($imagePath);
       // Print the secure URL from the response
       echo "<pre>***** Uploaded $imagePath: " . $response['secure_url'] . "</pre>";
    }

    Upload a single image from a remote URL

    Jump to this spot in the video  1:52 You can also upload images hosted online by passing the image's direct URL instead of a local file path. Cloudinary will download and store the file:
    PHP
    $response = $upload->upload("https://raw.githubusercontent.com/cloudinary-devs/cld-docs-assets/refs/heads/main/assets/images/people-walking.jpg");
    
    // Print the secure URL from the response
    echo "<pre>***** Uploaded remote image: " . $response['secure_url'] . "</pre>";

    Keep learning

    Related topics

    If you like this, you might also like...

     

    Cloudinary Academy

     

    Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.

     

    ✔️ Feedback sent!