简体   繁体   English

如何使用PHP访问架构空间打开的云容器并将文件上传到文件夹?

[英]How to access and upload files into folders on rackspace open cloud container using PHP?

I am using composer package 'rackspace/php-opencloud' installed with 我使用的是作曲家包'rackspace / php-opencloud'

composer require rackspace/php-opencloud

and trying to upload and get the list of files inside the folder 并尝试上传并获取文件夹中的文件列表

included the autoload file and add 包括自动加载文件并添加

require 'vendor/autoload.php';

using the process given on document http://docs.php-opencloud.com/en/latest/services/object-store/index.html but I do not get the solution to access the folders inside a container(recipes in my case). 使用文档http://docs.php-opencloud.com/en/latest/services/object-store/index.html上给出的过程,但我没有获得访问容器内的文件夹的解决方案(在我的案例中的食谱) )。 How can I upload the files into the directory "images" and "uploads" present inside container "recipes". 如何将文件上传到容器“食谱”中的“images”和“uploads”目录中。

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

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

$containers = $service->listContainers(); $ 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());
}

By the above code, I am able to access the the list of container and I can set the container and can fetch the list of 通过上面的代码,我可以访问容器列表,我可以设置容器,并可以获取列表

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

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

And they clearly explain that we cannot create new container inside any container we can pass subdirectory then pass name of the object like explained below: 并且他们清楚地解释了我们无法在任何容器内创建新容器,我们可以传递子目录然后传递对象的名称,如下所述:

While you cannot create nested containers, Cloud Files does support subdirectories, or subfolders. 虽然您无法创建嵌套容器,但Cloud Files确实支持子目录或子文件夹。 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 例如,如果您希望对象的相对URL为/images/kittens/thumbnails/kitty.png,请使用该相对路径作为对象名称将对象上载到容器

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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