PHP Additional topics
Overview
Cloudinary is a cloud-based service that provides an end-to-end image management solution including uploads, storage, administration, image manipulation, and delivery.
Cloudinary's PHP library wraps Cloudinary's upload API for easily uploading images and raw files to the cloud. In addition, the PHP library simplifies the generation of image manipulation URLs and includes view helper methods for embedding images and transformed images in your web views.
This page includes additional details regarding the integration of Cloudinary with your PHP applications.
Configuration options
Setting the configuration parameters can be done either programmatically in each call to a Cloudinary method or globally using an environment variable or the config method.
Your cloud_name account parameter is required to build image URLs. api_key and api_secret are further needed to perform secure API calls to Cloudinary (e.g., image uploads). See API, URLs and access identifiers for more details.
You can find your configuration parameters in the dashboard of our Management Console.
Here's an example of setting configuration parameters globally in your PHP application:
\Cloudinary::config(array( "cloud_name" => "sample", "api_key" => "874837483274837", "api_secret" => "a676b67565c6767a6767d6767f676fe1" ));
You can always override the values by passing different values in specific Cloudinary calls.
Another configuration option allows you to dynamically configure the Cloudinary library by defining the CLOUDINARY_URL environment variable. The configuration URL is available in the Management Console's dashboard of your account. When using Cloudinary through a PaaS add-on (e.g., AppFog), this environment variable is automatically defined in your deployment environment. Here's a sample value:
CLOUDINARY_URL=cloudinary://874837483274837:a676b67565c6767a6767d6767f676fe1@sample
In addition to the three mandatory configuration parameters mentioned above, you can define various optional configuration parameters either globally or for each API call specifically. Optional parameters:
- cdn_subdomain - Boolean (default: FALSE). Whether to automatically build URLs with multiple CDN sub-domains. See this blog post for more details.
- private_cdn - Boolean (default: FALSE). Should be set to true for Advanced plan's users that have a private CDN distribution.
- secure_distribution - The domain name of the CDN distribution to use for building HTTPS URLs. Relevant only for Advanced plan's users that have a private CDN distribution.
- cname - Custom domain name to use for building HTTP URLs. Relevant only for Advanced plan's users that have a private CDN distribution and a custom CNAME.
- secure - Boolean (default: FALSE). Force HTTPS URLs of images even if embedded in non-secure HTTP pages.
Admin API
While using Cloudinary, all your images are uploaded to the cloud. You can use our Media Library web interface to browse through your uploaded images and generated transformations.
In addition, you can use Cloudinary's administrative API: an intuitive RESTful HTTP API for programmatically managing all of your Cloudinary hosted assets. Main supported operations:
- Listing all uploaded images and raw files.
- Receiving details and metadata for uploaded images, including timestamps, format, dimensions, etc.
- Listing the derived images of uploaded images.
- Finding all images that share a given tag.
- Listing all transformations.
- Listing tags.
- Receiving transformation details.
- Creating named transformations.
- Updating an existing transformation.
- Deleting images, raw files, derived images and transformations.
For example, the following PHP command returns the details of an uploaded image according to its public ID:
$api = new \Cloudinary\Api(); $result = $api->resource("sample"); # Sample output: Cloudinary\Api\Response Object ( [rate_limit_reset_at] => 1373220000 [rate_limit_allowed] => 500 [rate_limit_remaining] => 499 [storage:ArrayObject:private] => Array ( [public_id] => sample [format] => jpg [version] => 1371282172 [resource_type] => image [type] => upload [created_at] => 2012-07-01T11:10:57Z [bytes] => 120264 [width] => 864 [height] => 576 [url] => http://res.cloudinary.com/demo/image/upload/v1371282172/sample.jpg [secure_url] => https://.../demo/image/upload/v1371282172/sample.jpg [next_cursor] => c87e7b39f7fdd66ec31985196b455c40 [derived] => Array ( [0] => Array ( [transformation] => c_fit,h_150,w_100 [format] => jpg [bytes] => 5729 [id] => 1892cd020611691462a8dc6616f81881 [url] => http://.../image/upload/c_fill,w_100,h_100/v1312461204/sample.jpg [secure_url] => https://.../c_fill,w_100,h_100/v1312461204/sample.jpg ) [1] => Array ( [transformation] => w_230,h_168,c_fit [format] => jpg [bytes] => 19173 [id] => 383e22a57167445552a3cdc16f0a0c85 [url] => http://.../image/upload/w_230,h_168,c_fit/v1312461204/sample.jpg [secure_url] => https://.../upload/w_230,h_168,c_fit/v1312461204/sample.jpg ) ) ) )
For a general overview and more examples, see this blog post: RESTful API for managing your website's images and other online assets
For more details, see our complete reference of the Admin API.