Rackspace cloudfiles PHP API创建容器而不是对象.每次都有不同的错误?

use*_*993 2 php curl rackspace

这是我使用PHP在我的rackspace帐户中上传图像的简单代码:

<?php

$api_username = 'lolcat';
$api_key = 'sexyapi';


require 'cloudfiles.php';

$auth = new CF_Authentication($api_username, $api_key);
$auth->authenticate();

$connection = new CF_Connection($auth);
$images = $connection->create_container("pitch");

$url = $images->make_public();
echo 'The url is '.$url;
$file = 'sherlock.jpg';
$img = $images->create_object($file);
$img->load_from_filename($file)
?>
Run Code Online (Sandbox Code Playgroud)

每次它都会产生不同的错误.像:"严格的标准:只有变量应该在1969行的C:\ wamp\www\cloudfiles.php中通过引用传递"

"致命错误:在1249行的C:\ wamp\www\cloudfiles_http.php中超出了30秒的最大执行时间"

错误样本(imgur图像)

请帮助我现在尝试这个简单的事情2个小时.

小智 6

不推荐使用Php-cloudfiles绑定.我建议你试试php-opencloud.我不应该很难移植你的代码.这是一个简单的例子:

<?php

require 'vendor/autoload.php';

use OpenCloud\Rackspace;

$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
    'username' => 'foo',
    'apiKey'   => 'bar'
));

$service = $client->objectStoreService('cloudFiles', 'DFW');

$container = $service->createContainer('pitch');
$container->enableCdn();

$cdn = $container->getCdn();
//Print "Container SSL URL: " . serialize($cdn);

$files = array(
    array(
        'name' => 'file_1.txt',
        'body' => fopen('files/file_1.txt', 'r+')
    )
);

$container->uploadObjects($files);
Run Code Online (Sandbox Code Playgroud)

您可以在以下网址找到php-opencloud文档:https://github.com/rackspace/php-opencloud/blob/master/docs/getting-started.md