简体   繁体   中英

Rackspace OpenCloud File PHP API nested containers problems

Hi I am currently using the Rackspace OpenCloud File PHP API for the file storage in a different project however I have a requirement to use nested containers.

I have a piece of software on a local pc which is mapped to a container called /Act/

I need to point to the Act folder as default instead of the root folder.

for example:

/act/12 - Test Company/

instead of

/12 - Test Company/

<?php
    $query = "SELECT clientNAME FROM CRM_clients WHERE clientID = '$client'";
    $result = mysqli_query($db, $query); 
    $rows = mysqli_num_rows($result);
    $row = clean_fetch_assoc($result);
    $name = $row['clientNAME'];

    $containers = $objectStoreService->listContainers();

    var_dump($containers);

    $ContainerExists = 0;

    foreach ($containers as $container) {
        $ContainerName = $container->name;
        if ( strpos($ContainerName, $client) !== false ) {
            $ContainerExists = 1;
        }
    }

    if ( $ContainerExists == 1 ) {
        $containerCONCAT = $client . " - " . $name;
        $container = $objectStoreService->getContainer($containerCONCAT);
    }elseif ( $ContainerExists == 0 ) {
        $containerCONCAT = $client . " - " . $name;
        $container = $objectStoreService->createContainer($containerCONCAT);
        $container = $objectStoreService->getContainer($containerCONCAT);
    }

    //Get list of files
    $objects = $container->objectList();
?>

any ideas?

There are a few convenience methods that you can use.

When listing containers can filter by their prefix:

$containers = $service->listContainers(['prefix' => $client]);

And to check whether a container exists, you can use:

$name = sprintf("%s-%s", $client, $container->name);

if ($service->containerExists($name)) {

Apart from that, you should be able to do what you want to do.

If you're running into specific errors, please post them here or send a HTTP stack trace to the support e-mail listed on their developer page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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