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
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
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
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
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
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
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
- Learn more about uploading images and videos using the PHP SDK.
- Take a look at our Upload guide to learn about uploading to Cloudinary in general.
- Use the Upload API reference to find all the options and parameters available.
- Watch more Dev Hints videos on the Cloudinary YouTube channel.
If you like this, you might also like...
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.
✖️