Php 如何从Rackspace';云文件及其api?
我想知道如何使用Rackspace的云文件API从其云文件中删除文件 我正在使用php Devan使用CF_容器的方法。这是我用C#编写的代码。只是猜测api与php类似Php 如何从Rackspace';云文件及其api?,php,file,rackspace,upload,Php,File,Rackspace,Upload,我想知道如何使用Rackspace的云文件API从其云文件中删除文件 我正在使用php Devan使用CF_容器的方法。这是我用C#编写的代码。只是猜测api与php类似 UserCredentials userCredientials = new UserCredentials("xxxxxx", "99999999999999"); cloudConnection = new Connection(userCredientials); cloudConnection.
UserCredentials userCredientials = new UserCredentials("xxxxxx", "99999999999999");
cloudConnection = new Connection(userCredientials);
cloudConnection.DeleteStorageItem(ContainerName, fileName);
确保设置了容器并定义了正在使用的任何sudo文件夹
$my_container = $this->conn->get_container($cf_container);
//delete file
$my_container->delete_object($cf_folder.$file_name);
我想我会在这里发布,因为没有一个答案被标记为正确答案,尽管我会接受Matthew Flaschen的答案作为正确答案。这就是删除文件所需的全部代码
<?php
require '/path/to/php-cloudfiles/cloudfiles.php';
$username = 'my_username';
$api_key = 'my_api_key';
$full_object_name = 'this/is/the/full/file/name/in/the/container.png';
$auth = new CF_Authentication($username, $api_key);
$auth->ssl_use_cabundle();
$auth->authenticate();
if ( $auth->authenticated() )
{
$this->connection = new CF_Connection($auth);
// Get the container we want to use
$container = $this->connection->get_container($name);
$object = $container->delete_object($full_object_name);
echo 'object deleted';
}
else
{
throw new AuthenticationException("Authentication failed") ;
}
使用classCF\u Container中名为DeleteObject的方法
CF\u容器的方法DeleteObject只需要一个字符串参数object\u name。
此参数应为要删除的文件名
参见下面的示例C#代码:
string username = "your-username";
string apiKey = "your-api-key";
CF_Client client = new CF_Client();
UserCredentials creds = new UserCredentials(username, apiKey);
Connection conn = new CF_Connection(creds, client);
conn.Authenticate();
var containerObj = new CF_Container(conn, client, container);
string file = "filename-to-delete";
containerObj.DeleteObject(file);
注意不要使用class*CF\u客户端中的DeleteObject*