我是新手......但我尝试使用Image
将PHP
上传到我的Cloudinary API帐户。但是我一直收到以下错误;即使我已经提供API_KEY
和API_Secret
。
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Must supply api_key' in C:\xampp\htdocs\-\php\Cloudinary.php:786
Stack trace: #0 C:\xampp\htdocs\-\php\Uploader.php(247):
Cloudinary::sign_request(Array, Array) #1 C:\xampp\htdocs\-\php\Uploader.php(62):
Cloudinary\Uploader::call_api('upload', Array, Array, 'C:\\xampp\\tmp\\ph...') #2 C:\xampp\htdocs\-\php\addProverbs.php(12):
Cloudinary\Uploader::upload('C:\\xampp\\tmp\\ph...') #3 {main} thrown in C:\xampp\htdocs\-\php\Cloudinary.php on line 786
在我的PHP
我提供了详细信息,如下所示......
<?php
$prov = json_decode(file_get_contents("php://input"));
require_once("connection.php");
require 'Cloudinary.php';
require 'Uploader.php';
require 'Api.php';
$connection = connectToMySQL();
$proverbDescription = $prov->proverbDescription;
$proverbNumber = $prov->proverbNumber;
$imgPath = $prov->imgPath;
$cloudUpload = \Cloudinary\Uploader::upload($_FILES["imgPath"]['tmp_name']);
\Cloudinary::config(array(
"cloud_name" => "xxxxxx",
"api_key" => "xxxxxxx", //hidden for obvious reasons
"api_secret" => "xxxxxxxx"
));
if (isset($_POST["submit"])) {
print_r($_FILES["imgPath"]);
$cloudUpload = \Cloudinary\Uploader::upload($_FILES["imgPath"]['tmp_name']);
print_r($cloudUpload);
}
$query = "INSERT INTO tbl_proverb (proverbDescription, proverbNumber, imgPath) VALUES ('$proverbDescription', '$proverbNumber', '$cloudUpload')";
$result = mysqli_query($connection, $query)
or die("Error in query: ". mysqli_error($connection));
if(mysqli_affected_rows($connection) > 0){
$success = true;
}else{
$success = false;
}
?>
这是我的HTML
表单,其中包含Image Upload
和2 textboxes
。
<form id="demo" class="collapse" action="php/addProverbs.php" ng-submit="addProverb(prov)" enctype="multipart/form-data" method="POST">
<label>Image:</label>
<input type="file" ng-model="prov.imgPath" name="imgPath" id="imgPath" accept="image/*">
<label>Proverb Description:</label>
<input type="text" ng-model="prov.proverbDescription" ><br><br>
<label>Proverb Number:</label>
<input type="text" ng-model="prov.proverbNumber"><br><br>
<input type="submit" name="submit"><br>
<a href="#/proverbs">See your post</a>
</form>
对不起基本问题,但我对此很新。
非常感谢!