SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 1 Java
2022-07-18 08:54:58 -07:00
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
namespace AwsUtilities;
2022-07-18 09:07:37 -07:00
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Utils;
use ZipArchive;
2022-07-18 08:54:58 -07:00
function loadMovieData()
{
$movieFileName = 'moviedata.json';
$movieZipName = 'moviedata.zip';
$url = 'https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/samples/moviedata.zip';
$guzzle = new GuzzleClient(['verify' => false]);
$file = Utils::tryFopen($movieZipName, 'w');
try {
$guzzle->request("get", $url, ['sink' => $file]);
} catch (GuzzleException $e) {
echo "Could not retrieve remote file. {$e->getCode()}: {$e->getMessage()}\n";
return null;
}
2022-07-18 08:54:58 -07:00
$zip = new ZipArchive();
$extractPath = ".";
if ($zip->open($movieZipName) !== true) {
2022-07-19 16:33:50 -07:00
echo "Could not open or find the zip file. Check your file system permissions.";
2022-07-18 08:54:58 -07:00
}
$zip->extractTo($extractPath);
$zip->close();
return file_get_contents($movieFileName);
2022-07-18 09:07:37 -07:00
}