-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathLoadMovieData.php
36 lines (30 loc) · 1.06 KB
/
LoadMovieData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
namespace AwsUtilities;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Utils;
use ZipArchive;
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;
}
$zip = new ZipArchive();
$extractPath = ".";
if ($zip->open($movieZipName) !== true) {
echo "Could not open or find the zip file. Check your file system permissions.";
}
$zip->extractTo($extractPath);
$zip->close();
return file_get_contents($movieFileName);
}