Cloudinary API and CodeIgniter

Integrate Cloudinary PHP API Library into CodeIgniter:

1. Clone this project out on GitHub if you haven't already.

2. In the CodeIgniter "application/libraries" folder, put your "cloudinary" folder (containing the Cloudinary PHP API library) and the file called Cloudinarylib.php (located in the "cloudinary-for-codeigniter" folder).

3. Open the "Cloudinarylib.php" file and replace the placeholder API connect info with your actual API connect info:

defined('BASEPATH') OR exit('No direct script access allowed');

// setup the dummy class for Cloudinary
class Cloudinarylib {

    public function __construct()

        // include the cloudinary library within the dummy class
        require 'cloudinary/src/Uploader.php';
        require 'cloudinary/src/Api.php';

            "cloud_name" => "your_cloud_name",
            "api_key" => "your_api_key", /*874837483274837*/
            "api_secret" => "your_api_secret" /* a676b67565c6767a6767d6767f676fe1 */

Using The Cloudinary Library Within CodeIgniter

4. Once the above steps are completed, your Cloudinary API library will be availabe via the "cloudinarylib" name and can be loaded like any other CodeIgniter library.

Below is from the CodeIgniter sample site within the Example folder which uses the standard welcome page controller and the "sample" image from Cloudinary:

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public function __construct()

			// load the cloudinary dummy library

	public function index()

		// execute cloudinary api call to grab sample image and assign to $image variable in the view
		$data['image'] = cl_image_tag("sample.jpg", array( "alt" => "Sample Image" ));

        /* The rest of the Cloudinary library is available using it's namespace "\Cloudinary\"
        To see it in action, uncomment code line below and replace "url_to_image" with an image url
        and when the welcome page loads it will upload to your Cloudinary account and return a response object
        in the $data['imageupload'] array.

        -- See Cloudinary PHP API docs for additional examples.

        //$data['imageupload'] = \Cloudinary\Uploader::upload("");


In the view, you echo the variable like you normally would:

<?php echo $image; ?>

If done correctly, your image should load here:

Sample Image

As for the rest of the library, now you can access it by using the "\Cloudinary\" namespace in whichever class you have loaded the Cloudinary library.

            $data['imageupload'] = \Cloudinary\Uploader::upload("");

This example will execute the image upload when the Welcome page loads.