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
2024-01-31 08:10:26 -07:00
namespace AwsUtilities ;
2022-07-18 09:07:37 -07:00
2024-01-31 08:10:26 -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 ]);
2024-01-31 08:10:26 -07:00
$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
}