get_object_filesize ( $bucket, $filename, $friendly_format )

Gets the file size of the specified Amazon S3 object.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$filename

string

Required

The file name for the object.

$friendly_format

boolean

Optional

A value of true will format the return value to 2 decimal points using the largest possible unit (i.e., 3.42 GB). A value of false will format the return value as the raw number of bytes.

Returns

Type

Description

integer
string
boolean

The number of bytes as an integer, or the friendly format as a string. Returns false if the request failed.

Examples

Get the size of the object, in bytes.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

$response = $s3->get_object_filesize($bucket, 'video/sample.mp4');

// Success?
var_dump($response);

Get the size of the object, measured in the largest reasonable unit.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

$response = $s3->get_object_filesize($bucket, 'video/sample.mp4', true);

// Success?
var_dump($response);

Related Methods

Source

Method defined in services/s3.class.php | Toggle source view (21 lines) | View on GitHub

public function get_object_filesize($bucket, $filename, $friendly_format = false)
{
    if ($this->use_batch_flow)
    {
        throw new S3_Exception(__FUNCTION__ . '() cannot be batch requested');
    }

    $response = $this->get_object_headers($bucket, $filename);
    if (!$response->isOK()) {
        return false;
    }

    $filesize = (integer) $response->header['content-length'];

    if ($friendly_format)
    {
        $filesize = $this->util->size_readable($filesize);
    }

    return $filesize;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback