这简直要了我的命。我做了所有事情,但都不对,因为它仍然没有给我这个错误
Fatal error: Uncaught exception 'CFCredentials_Exception' with message 'No credentials were provided
。我正在尝试使用 AWS sdk 1.6 示例和 jquery 文件上传插件将文件上传到 S3。我在wiki上找到了一个示例。
这是我的文件,我在其中设置awssdk.php
了 wiki 示例中的凭据
require_once 'sdk.class.php';
require_once 'utilities.class.php';
require_once 'credential.class.php';
if (!class_exists('CFCredentials'))require_once('credentials.class.php');
$name=null;
CFCredentials::set(array(
$name => array(
'key' => 'access key',
'secret' => 'secret key',
'certificate_authority' => false
),
'@default' => $name
));
if (!class_exists('S3'))require_once('S3.php');
$s3 = new AmazonS3();
我很确定我不应该需要这么多文件,但正如错误所暗示的那样,我必须添加依赖类。但我仍然收到上述错误。我还尝试包含config.class.php
凭据文件,但仍然出现此错误。
我在这方面花了很多时间,现在对这个 AWS sdk 有点失望。
我对 OO PHP 有点陌生,因此可能觉得它很困难。专家请提出一些解决方案来解决我的错误。
编辑:我相信这门课会导致问题,不知道怎么回事!!
class CFCredentials
{
/**
* The key used to specify the default credential set
*/
const DEFAULT_KEY = 'my key';
/**
* The key used to identify inherited credentials
*/
const INHERIT_KEY = 'my secret key';
/**
* Stores the credentials
*/
protected static $credentials = array();
/**
* Prevents this class from being constructed
*/
final private function __construct() {}
/**
* Stores the credentials for re-use.
*
* @param array $credential_sets (Required) The named credential sets that should be made available to the application.
* @return void
*/
// private $credential_sets = array('key' => 'xxxxxxxxxxxxxxxxxxxx','secret' => 'xxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxx','certificate_authority' => false);
public static function set(array $credential_sets)
{
// Make sure a default credential set is specified or can be inferred
if (count($credential_sets) === 1)
{echo "in count if-->".self::DEFAULT_KEY;
$credential_sets[self::DEFAULT_KEY] = reset($credential_sets);
}
// Resolve any @inherit tags
foreach ($credential_sets as $credential_name => &$credential_set)
{
if (is_array($credential_set))
{
foreach ($credential_set as $credential_key => &$credential_value)
{
if ($credential_key === self::INHERIT_KEY)
{
if (!isset($credential_sets[$credential_value]))
{
throw new CFCredentials_Exception('The credential set, "' . $credential_value . '", does not exist and cannot be inherited.');
}
$credential_set = array_merge($credential_sets[$credential_value], $credential_set);
unset($credential_set[self::INHERIT_KEY]);
}
}
}
}
// Normalize the value of the @default credential set
if (isset($credential_sets[self::DEFAULT_KEY]))
{
$default = $credential_sets[self::DEFAULT_KEY];
if (is_string($default))
{
if (!isset($credential_sets[$default]))
{
throw new CFCredentials_Exception('The credential set, "' . $default . '", does not exist and cannot be used as the default credential set.');
}
$credential_sets[self::DEFAULT_KEY] = $credential_sets[$default];
}
}
// Store the credentials
self::$credentials = $credential_sets;
}
/**
* Retrieves the requested credentials from the internal credential store.
*
* @param string $credential_set (Optional) The name of the credential set to retrieve. The default value is set in DEFAULT_KEY.
* @return stdClass A stdClass object where the properties represent the keys that were provided.
*/
public static function get($credential_name = self::DEFAULT_KEY)
{
//echo $credential_name; exit;
// Make sure the credential set exists
if (!isset(self::$credentials[$credential_name]))
{
throw new CFCredentials_Exception('The credential set, "' . $credential_name . '", does not exist and cannot be retrieved.');
}
// Return the credential set as an object
return new CFCredential(self::$credentials[$credential_name]);
}
/**
* Retrieves a list of all available credential set names.
*
* @return CFArray A list of all available credential set names.
*/
public static function list_sets()
{
return new CFArray(array_keys(self::$credentials));
}
}
class CFCredentials_Exception extends Exception {}
谢谢