简体   繁体   中英

Rackspace cloudfiles PHP API creating container but not objects . Different errors everytime?

This is the simple code I`m using to upload an image in my rackspace account with 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)
?>

Also everytime it gives diffrent errors. Like: "Strict standards: Only variables should be passed by reference in C:\\wamp\\www\\cloudfiles.php on line 1969 "

" Fatal error: Maximum execution time of 30 seconds exceeded in C:\\wamp\\www\\cloudfiles_http.php on line 1249"

A sample of errors (imgur image)

Please help I`ve been trying this simple thing for 2 hours now.

Php-cloudfiles bindings are deprecated. I suggest you to give php-opencloud a try. I shouldn't be hard to port your code. Here's a quick example:

<?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);

You can find php-opencloud docs at: https://github.com/rackspace/php-opencloud/blob/master/docs/getting-started.md

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM