这是我用于在我的rackspace帐户中使用PHP上传图像的简单代码:
<?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)
?>
每次它都会出现不同的错误。喜欢: “严格的标准:在1969行的C:\ wamp \ www \ cloudfiles.php中只能通过引用传递变量”
“致命错误:在1249行的C:\ wamp \ www \ cloudfiles_http.php中超出了30秒的最长执行时间”
A sample of errors (imgur image)
请帮助我在2小时内尝试这个简单的事情。
答案 0 :(得分: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);
您可以在https://github.com/rackspace/php-opencloud/blob/master/docs/getting-started.md
找到php-opencloud文档