问题
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:
- First You need to download the cloudinary php script here https://github.com/cloudinary/cloudinary_php.
- Now extract the downloaded file and copy the files from src folder.
- 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:
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" ));
Now to upload:
$data['upload'] = \Cloudinary\Uploader::upload("image url you want to download");
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