Skip to content

Commit 88cc65c

Browse files
php app
1 parent 73356b2 commit 88cc65c

File tree

5 files changed

+1018
-0
lines changed

5 files changed

+1018
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

examples/php_credentials/README

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## PHP Quick Start with Cloudinary
2+
3+
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.
4+
5+
### Prerequisites
6+
7+
* PHP (version 7.4 or higher recommended)
8+
* Composer for dependency management
9+
* A Cloudinary account (you can sign up here if you don’t have one)
10+
11+
12+
### Installation
13+
14+
1. Clone the repository:
15+
```
16+
git clone https://github.com/your-username/php-cloudinary-quickstart.git
17+
cd php-cloudinary-quickstart
18+
```
19+
20+
2. Install dependencies: <p>Run the following command to install PHP dependencies using Composer:</p>
21+
```
22+
composer install
23+
```
24+
25+
3. Set up environment variables:
26+
* Create a .env file in the root of your project.
27+
* Add your Cloudinary URL (from your Cloudinary dashboard) in the `.env` file like this:
28+
```
29+
CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME
30+
```
31+
32+
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.
33+
34+
### Usage
35+
36+
1. Start a local server: You can use the built-in PHP server to serve the file:
37+
```
38+
php -S localhost:8000
39+
```
40+
41+
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.
42+
43+
### Code Explanation
44+
45+
* **Dotenv**: This project uses `vlucas/phpdotenv` to load environment variables from a `.env` file.
46+
* **Cloudinary PHP SDK**: The code configures Cloudinary using credentials from `.env` and generates an image tag with a transformation (resizing to 400px width).
47+
* **Image transformation**: The example includes a resize transformation for the sample image using Resize::scale().
48+
49+
### Example Output
50+
51+
The program will display the following HTML image tag (adjusted for the Cloudinary demo account):
52+
53+
```
54+
<img src="https://res.cloudinary.com/demo/image/upload/b_auto:predominant,c_pad,h_400,w_400/flower_sample">
55+
```
56+
57+
### Dependencies
58+
59+
* `vlucas/phpdotenv` for environment variable management
60+
* Cloudinary PHP SDK for managing Cloudinary assets
61+
62+
### License
63+
64+
This project is licensed under the MIT License.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "sharon-yelenik/php_credentials_test",
3+
"description": "My first PHP project",
4+
"type": "project",
5+
"require": {
6+
"cloudinary/cloudinary_php": "^2"
7+
},
8+
"license": "MIT",
9+
"authors": [
10+
{
11+
"name": "sharon-yelenik",
12+
"email": "[email protected]"
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)