Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awsdocs
GitHub Repository: awsdocs/amazon-s3-developer-guide
Path: blob/master/code_examples/php_examples/S3examples/s3-multipart-upload-using-multipartuploader.php
4084 views
1
<?php
2
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
// SPDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/LICENSE-SAMPLECODE )
4
5
require 'vendor/autoload.php';
6
7
use Aws\Common\Exception\MultipartUploadException;
8
use Aws\S3\MultipartUploader;
9
use Aws\S3\S3Client;
10
11
$bucket = '*** Your Bucket Name ***';
12
$keyname = '*** Your Object Key ***';
13
14
$s3 = new S3Client([
15
'version' => 'latest',
16
'region' => 'us-east-1'
17
]);
18
19
// Prepare the upload parameters.
20
$uploader = new MultipartUploader($s3, '/path/to/large/file.zip', [
21
'bucket' => $bucket,
22
'key' => $keyname
23
]);
24
25
// Perform the upload.
26
try {
27
$result = $uploader->upload();
28
echo "Upload complete: {$result['ObjectURL']}" . PHP_EOL;
29
} catch (MultipartUploadException $e) {
30
echo $e->getMessage() . PHP_EOL;
31
}
32
33