This is a simple PHP project that demonstrates how to configure and use Cloudinary for image management. The program loads Cloudinary credentials from a .env file, generates an image tag with specified transformations, and outputs it to the browser.
- PHP (version 7.4 or higher recommended)
- Composer for dependency management
- A Cloudinary account (you can sign up here if you don’t have one)
-
Clone the repository:
git clone https://github.com/cloudinary-devs/php_credentials.git cd php_credentials
-
Install dependencies:
Run the following command to install PHP dependencies using Composer:
composer install
-
Set up environment variables:
- Create a .env file in the root of your project.
- Add your Cloudinary URL (from the API Keys page in the Console Settings) in the
.env
file like this:CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME
-
This project uses
vlucas/phpdotenv
to load environment variables, so make sure your.env
file is in the same directory as your PHP file.
-
Start a local server: You can use the built-in PHP server to serve the file:
php -S localhost:8000
-
Access the program: Open your browser and go to
http://localhost:8000
to see the output, which will display a Cloudinary image with specified transformations.
- Dotenv: This project uses
vlucas/phpdotenv
to load environment variables from a.env
file. - Cloudinary PHP SDK: The code configures Cloudinary using credentials from
.env
and generates an image tag with a transformation (resizing to 400px width). - Image transformation: The example includes a resize transformation for the sample image using Resize::scale().
The program will display the following HTML image tag:
<img src="https://res.cloudinary.com/my-shop/image/upload/c_scale,w_400/cld-sample">
vlucas/phpdotenv
for environment variable management- Cloudinary PHP SDK for managing Cloudinary assets
This project is licensed under the MIT License.