Todos los productos
Search
Centro de documentos

Object Storage Service:Gestión de enlaces simbólicos (PHP SDK V1)

Última actualización: Sep 03, 2026

Los enlaces simbólicos funcionan como accesos directos en Windows y permiten acceder rápidamente a los objetos asociados en Object Storage Service (OSS).

Notas de uso

  • En este tema se utiliza el endpoint público de la región China (Hangzhou). Para acceder a OSS desde otros servicios de Alibaba Cloud en la misma región, use un endpoint interno. Para obtener más información sobre las regiones y endpoints compatibles, consulte Regions and endpoints.

  • Este tema muestra cómo crear una instancia de OSSClient con un endpoint de OSS. Para configuraciones alternativas, como el uso de un dominio personalizado o la autenticación con credenciales de Security Token Service (STS), consulte Create an OssClient.

  • Para crear un enlace simbólico, debe contar con el permiso oss:PutObject. Para recuperar un enlace simbólico, debe tener el permiso oss:GetObject. Para obtener más información, consulte Grant custom permissions to a RAM user.

Crear un enlace simbólico

A continuación se presenta un ejemplo de código para crear un enlace simbólico:

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;

// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// This example uses the endpoint of the China (Hangzhou) region. Replace the endpoint with the one for your region.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the bucket name. For example, examplebucket.
$bucket= "examplebucket";
// Specify the name of the object to which the symbolic link points. For example, exampleobject.txt.
$object = "exampleobject.txt";
// Specify the name of the symbolic link. For example, examplesymlink.txt.
$symlink = "examplesymlink.txt";

$options[OssClient::OSS_HEADERS] = array(
    // Specify whether to overwrite an object that has the same name. This example sets the value to true, which prevents overwriting.
    'x-oss-forbid-overwrite'=>"true",
    // Specify the object's access control list (ACL). This example sets the ACL to private, which means only the object owner and authorized users have read and write permissions.
    'x-oss-object-acl' =>"private",
    // Specify the storage class of the object. This example sets the storage class to Standard.
    'x-oss-storage-class' =>"Standard"
);
try {
    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        "region"=> "cn-hangzhou"
    );
    $ossClient = new OssClient($config);
    $ossClient->putSymlink($bucket, $symlink, $object,$options);
} catch (OssException $e) {
    printf($e->getMessage() . "\n");
    return;
}

Obtener el objeto destino de un enlace simbólico

Para consultar un enlace simbólico, debe tener permisos de lectura sobre dicho enlace. El siguiente código de ejemplo muestra cómo consultar un enlace simbólico y obtener el nombre del objeto al que apunta:

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;

// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// This example uses the endpoint of the China (Hangzhou) region. Replace the endpoint with the one for your region.
$endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// Specify the bucket name.
$bucket= "examplebucket";
// Specify the name of the symbolic link.
$symlink = "examplesymlink.txt";
try {
    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        "region"=> "cn-hangzhou"
    );
    $ossClient = new OssClient($config);
    // Get the symbolic link and the name of the object to which the symbolic link points.
    $Symlinks = $ossClient->getSymlink($bucket, $symlink);
} catch (OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");
var_dump($Symlinks);            

Referencias

  • Para consultar el código de ejemplo completo sobre enlaces simbólicos, consulte el ejemplo en GitHub.

  • Para obtener más información sobre la operación de API para crear un enlace simbólico, consulte PutSymlink.

  • Para obtener más información sobre la operación de API para recuperar un enlace simbólico, consulte GetSymlink.