2012-01-05 93 views
0

我使用PHP和我有一个像位于image/tomato.png相对于我的PHP文件。cloudfiles简单的图片上传

我设法让我cloudfile容器的列表,所以我知道我的Rackspace公司的认证工作正常。

问:如何使用PHP将图像文件上传到rackspace cloudfiles容器'phpx'

回答

1

有一个简单的cloudfiles API为PHP在github上绑定 - >https://github.com/rackspace/php-cloudfiles

使用范例:

<?php 

// include the API 
require('cloudfiles.php'); 

// cloud info 
$username = ""; // username 
$key = ""; // api key 

// Connect to Rackspace 
$auth = new CF_Authentication($username, $key); 
$auth->authenticate(); 
$conn = new CF_Connection($auth); 

// Get the container we want to use 
$container = $conn->get_container('container name'); 

// store file information 
$localfile = <filepath>; 
$filename = <filename>; 

// upload file to Rackspace 
$object = $container->create_object($filename); 
$object->load_from_filename($localfile); 

?> 
+0

谢谢ManseUK。我能问你从哪里找到这个例子? – David19801 2012-01-05 11:58:29

+0

@ David19801使用众所周知的搜索引擎... – ManseUK 2012-01-05 11:59:36