如何使用PHP从AWS Glacier获取/检索文件?

时间:2016-06-23 04:05:31

标签: php amazon-web-services

我正在尝试使用PHP获取/检索存储在AWS Glacier上的文件。但我无法找到任何方法。

我想要的只是使用PHP从AWS Glacier获取/检索。如果有人对此有所了解,那么请建议我。

感谢。

1 个答案:

答案 0 :(得分:1)

根据example from github,您可以使用以下

检索文件
// Use the us-west-2 region and latest version of each client.
$sharedConfig = [
    'region'  => 'us-west-2',
    'version' => 'latest'
];

// Create an SDK class used to share configuration across clients.
$sdk = new Aws\Sdk($sharedConfig);

// Create an Amazon Glacier client using the shared configuration data.
$client = $sdk-> createGlacier();

//Download our archive from Amazon to our server
$result = $aws->getJobOutput(array(
    'vaultName' => '<YOUR VAULT>',  //The name of the vault
    'jobId' => 'XXXX'  //supply the unique ID of the job that retrieved the archive 
));

$data = $result->get('body');  //Sets the file data to a variable
$description = $result->get('archiveDescription');  //Sets file description to a variable

//deletes the temp file on our server if it exists
if(file_exists("files/temp")){
    unlink("files/temp");
}

$filepath = "files/temp";  
$fp = fopen($filepath, "w");  //creates a new file temp file on our web server
fwrite($fp, $data);  //write the data in our variable to our temp file

//Your archive is now ready for download on your web server

您可以查看PHP Glacier ref documentation了解详情