gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:39:57 25 4
gpt4 key购买 nike

我正在使用安装的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com