php - 如何使用 PHP 访问文件并将其上传到 rackspace open cloud 容器上的文件夹中?

标签 php rackspace php-opencloud

我正在使用安装的 composer 包 'rackspace/php-opencloud'

composer require rackspace/php-opencloud

并尝试上传并获取文件夹内的文件列表

包括自动加载文件并添加

require 'vendor/autoload.php';

使用文档 http://docs.php-opencloud.com/en/latest/services/object-store/index.html 中给出的过程但我没有得到访问容器内文件夹的解决方案(在我的例子中是食谱)。如何将文件上传到容器“recipes”内的目录“images”和“uploads”。

$client = new OpenCloud\OpenStack('{keystoneUrl}', array(
  'username' => '{username}',
  'password' => '{apiKey}',
  'tenantId' => '{tenantId}',
));

$service = $client->objectStoreService('{catalogName}', '{region}', '{urlType}');

$containers = $service->listContainers();

foreach ($containers as $container) {
    /** @param $container OpenCloud\ObjectStore\Resource\Container */
    printf("Container name: %s\n", $container->name);
    printf("Number of objects within container: %d\n", $container->getObjectCount());
}

通过上面的代码,我可以访问容器列表,我可以设置容器并获取列表

$containers = $service->listContainers();
** @param $container OpenCloud\ObjectStore\Resource\Container */
$container = $service->getContainer('{containerName}');

最佳答案

我在rackspace网站上找到了答案: https://developer.rackspace.com/docs/cloud-files/quickstart/?lang=php

他们清楚地解释说我们不能在任何容器中创建新容器我们可以传递子目录然后传递对象的名称,如下所述:

While you cannot create nested containers, Cloud Files does support subdirectories, or subfolders. Objects are uploaded to a subdirectory through a special naming convention, by including the subdirectory path in the object name, separating path segments with the forward slash character /.

For example, if you want the relative URL of the object to be /images/kittens/thumbnails/kitty.png, upload the object to a container using that relative path as the object name

$object = $container->uploadObject('{subdirectories}/{object_name}', $handle);

关于php - 如何使用 PHP 访问文件并将其上传到 rackspace open cloud 容器上的文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45372203/

相关文章:

php - 选择某商品一个月内的最后一笔交易

java - Rackspace 云文件(使用 jclouds)——如何获取容器位置

php - 在 Ubuntu 上安装 Composer 后无法包含 "vendor/autoload.php"

Elasticsearch 自动发现机架空间不工作

mysql - 将数据库移动到远程服务器会减慢连接查询

php - serverList() 只返回 100 个结果

php - 更改时图像不显示

php - Laravel - 从表单中获取数据

php - 按 id 和 timedate 将多行分组并根据日期显示