PHP code example of ericnorris / amazon-s3-php

1. Go to this page and download the library: Download ericnorris/amazon-s3-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ericnorris / amazon-s3-php example snippets


curl_opts = array(
    CURLOPT_CONNECTTIMEOUT => 30,
    CURLOPT_LOW_SPEED_LIMIT => 1,
    CURLOPT_LOW_SPEED_TIME => 30
);

class S3Response {
    public $error;    // null if no error
    public $code;     // response code from AWS
    public $headers;  // response headers from AWS
    public $body;     // response body from AWS
}

$client = new S3(ACCESS_KEY, SECRET_KEY);

// [OPTIONAL] Specify different curl options
$client->useCurlOpts(array(
    CURLOPT_MAX_RECV_SPEED_LARGE => 1048576,
    CURLOPT_CONNECTTIMEOUT => 10
));

$resource = tmpfile();
$client->getObject('bucket', 'hello_world.txt', $resource);

print_r($response);
echo stream_get_contents($resource) . "\n";

$error = array(
    'code' => xxx, // error code from either curl or AWS
    'message' => xxx, // error string from either curl or AWS
    'resource' => [optional] // the S3 resource frmo the request
)

$response = $client->putObject(
    'bucket',
    'hello_world.txt',
    'hello world!',
    array(
        'Content-Type' => 'text/plain'
    )
);

print_r($response);