Upload image to Cloudinary using PHP Codeigniter

2019-04-18 04:05发布

Can someone help me how to upload an image into Cloudninary using CodeIgniter? I don't know how to install the Cloudinary to CodeIgniter and use it because I'm new to PHP CodeIgniter. Please help me thank you.

Update! I was able to solve it. See the first answer. cheers

2条回答
淡お忘
2楼-- · 2019-04-18 04:42

This code works for me

Cloudinary::config(array(
    "cloud_name" => "cloud_name",
    "api_key" => "*****",
    "api_secret" => "*****"
));

$image = UploadedFile::getInstanceByName('file');

$cloudinaryImage = Cloudinary\Uploader::upload($image->tempName);

$entity->setFile($cloudinaryImage->url);
查看更多
相关推荐>>
3楼-- · 2019-04-18 04:53
  1. First You need to download the cloudinary php script here https://github.com/cloudinary/cloudinary_php.
  2. Now extract the downloaded file and copy the files from src folder.
  3. Now in you codeigniter app, go to appplication folder and then third_party folder. Inside the third_party folder create a folder name cloudinary, and inside cloudinary folder paste the files from src folder that you extracted lately.

To use the cloudinary library:

  1. Now inside your controller, in a function. You need to set up first the api credentials like this:

    require APPPATH .'third_party/cloudinary/Cloudinary.php';
    require APPPATH .'third_party/cloudinary/Uploader.php';
    require APPPATH .'third_party/cloudinary/Api.php';
    

    Cloudinary::config(array( "cloud_name" => "yourcloudname", "api_key" => "yourapikey", "api_secret" => "yoursecretkey" ));

  2. Now to upload:

    $data['upload'] = \Cloudinary\Uploader::upload("image url you want to download");

  3. And your done. for more information about the api you can then refer to the official documentation in http://cloudinary.com/documentation/php_integration.

查看更多
登录 后发表回答