Upload image to Cloudinary using PHP Codeigniter

江枫思渺然 提交于 2019-12-06 18:08:17

问题


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


回答1:


  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.




回答2:


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


来源:https://stackoverflow.com/questions/41722599/upload-image-to-cloudinary-using-php-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!