Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/php_credentials/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
64 changes: 64 additions & 0 deletions examples/php_credentials/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## PHP Quick Start with Cloudinary

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.

### Prerequisites

* 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)


### Installation

1. Clone the repository:
```
git clone https://github.com/your-username/php-cloudinary-quickstart.git
cd php-cloudinary-quickstart
```

2. Install dependencies: <p>Run the following command to install PHP dependencies using Composer:</p>
```
composer install
```

3. Set up environment variables:
* Create a .env file in the root of your project.
* Add your Cloudinary URL (from your Cloudinary dashboard) in the `.env` file like this:
```
CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME
```

4. This project uses `vlucas/phpdotenv` to load environment variables, so make sure your `.env` file is in the same directory as your PHP file.

### Usage

1. Start a local server: You can use the built-in PHP server to serve the file:
```
php -S localhost:8000
```

2. 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.

### Code Explanation

* **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().

### Example Output

The program will display the following HTML image tag (adjusted for the Cloudinary demo account):

```
<img src="https://res.cloudinary.com/demo/image/upload/b_auto:predominant,c_pad,h_400,w_400/flower_sample">
```

### Dependencies

* `vlucas/phpdotenv` for environment variable management
* Cloudinary PHP SDK for managing Cloudinary assets

### License

This project is licensed under the MIT License.
15 changes: 15 additions & 0 deletions examples/php_credentials/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "sharon-yelenik/php_credentials_test",
"description": "My first PHP project",
"type": "project",
"require": {
"cloudinary/cloudinary_php": "^2"
},
"license": "MIT",
"authors": [
{
"name": "sharon-yelenik",
"email": "sharon.yelenik@cloudinary.com"
}
]
}
Loading