php中没有设置云环境?

bvhaajcl  于 2023-05-21  发布在  PHP
关注(0)|答案(1)|浏览(109)

这是我第一次使用Cloudinary。我试图上传一个图像到cloudinary,但我得到一个错误,我的环境没有设置或设置不正确。
我不知道为什么它没有被设置,我只是复制了cloudinary说我必须做的事情。
cloudinary版本:"cloudinary/cloudinary_php": "^2.10"
这是我的代码:

require 'vendor/autoload.php';

use Cloudinary\Cloudinary;
use Cloudinary\Api\Upload\UploadApi;

$cloudinary = new Cloudinary(
    [
        'cloud' => [
            'cloud_name' => 'XXXXXXX',
            'api_key'    => 'XXXXXXXXXX',
            'api_secret' => 'XXXXXXXXXXXXXXXXX',
        ],
    ]
);

$uploadApi = new UploadApi($cloudinary);

$result = $uploadApi->upload("images/signup-image.jpg", [
  'folder' => 'promptopolis', // Optional: Specify a folder in Cloudinary
]);
  
print_r($result);

我收到的完整错误:
致命错误:未捕获的Cloudinary\Exception\ConfigurationException:配置无效,请在C:\xampp\htdocs\php\eindwerk\vendor\cloudinary\cloudinary_php\src\Configuration\Configuration中设置您的环境。php:179
堆栈跟踪:

0 C:\xampp\htdocs\php\eindwerk\vendor\cloudinary\cloudinary_php\src\Configuration\Configuration.php(138):Cloudinary\Configuration\Configuration->import(Object(Cloudinary\Cloudinary))

1 C:\xampp\htdocs\php\eindwerk\vendor\cloudinary\cloudinary_php\src\Configuration\Configuration.php(119):Cloudinary\Configuration\Configuration->init(Object(Cloudinary\Cloudinary),true)

\xampp\htdocs\php\eindwerk\vendor\cloudinary_php\src\API\ApiClient.php(88):Cloudinary\Configuration\Configuration->__construct(Object(Cloudinary\Cloudinary))

3 C:\xampp\htdocs\php\eindwerk\vendor\cloudinary\cloudinary_php\src\API\ApiClient.php(53):Cloudinary\API\ApiClient->配置(Object(Cloudinary\Cloudinary))

4 C:\xampp\htdocs\php\eindwerk\vendor\cloudinary\cloudinary_php\src\API\Upload\UploadApi.php(51):Cloudinary\API\ApiClient->__construct(Object(Cloudinary\Cloudinary))

C:\xampp\htdocs\php\eindwerk\test.php(17):Cloudinary\API\Upload\UploadApi->__construct(Object(Cloudinary\Cloudinary))

Copyright © 2018 - 2019 www.cnjs.com. All Rights Reserved.粤ICP备15048888号-1

h6my8fg2

h6my8fg21#

回复

使用此代码

(new UploadApi())->upload('images/signup-image.jpg');

而不是

$uploadApi = new UploadApi($cloudinary);

$result = $uploadApi->upload("images/signup-image.jpg", [
  'folder' => 'promptopolis', // Optional: Specify a folder in Cloudinary
]);

帮我修好了

相关问题