url_stat ( $path, $flags )

This method is called in response to all stat() related functions.

Access

public

Parameters

Parameter

Type

Required

Description

$path

string

Required

The file path or URL to stat. Note that in the case of a URL, it must be a :// delimited URL. Other URL forms are not supported.

$flags

integer

Required

Holds additional flags set by the streams API. This implementation ignores all defined flags.

Returns

Type

Description

array

Should return as many elements as stat() does. Unknown or unavailable values should be set to a rational value (usually 0).

Source

Method defined in extensions/s3streamwrapper.class.php | Toggle source view (96 lines) | View on GitHub

public function url_stat($path, $flags)
{
    // Defaults
    $out = array();
    $out[0] = $out['dev'] = 0;
    $out[1] = $out['ino'] = 0;
    $out[2] = $out['mode'] = 0;
    $out[3] = $out['nlink'] = 0;
    $out[4] = $out['uid'] = 0;
    $out[5] = $out['gid'] = 0;
    $out[6] = $out['rdev'] = 0;
    $out[7] = $out['size'] = 0;
    $out[8] = $out['atime'] = 0;
    $out[9] = $out['mtime'] = 0;
    $out[10] = $out['ctime'] = 0;
    $out[11] = $out['blksize'] = 0;
    $out[12] = $out['blocks'] = 0;

    $this->path = $path;
    list($protocol, $bucket, $object_name) = $this->parse_path($this->path);

    $file = null;
    $mode = 0;

    if ($object_name)
    {
        $response = $this->client($protocol)->list_objects($bucket, array(
            'prefix' => $object_name
        ));

        if (!$response->isOK())
        {
            return $out;
        }

        // Ummm... yeah...
        if (is_object($response->body))
        {
            $file = $response->body->Contents[0];
        }
        else
        {
            $body = simplexml_load_string($response->body);
            $file = $body->Contents[0];
        }
    }
    else
    {
        $response = $this->client($protocol)->list_objects($bucket);

        if (!$response->isOK())
        {
            return $out;
        }
    }

    /*
    Type & Permission bitwise values (only those that pertain to S3).
    Simulate the concept of a "directory". Nothing has an executable bit because there's no executing on S3.
    Reference: http://docstore.mik.ua/orelly/webprog/pcook/ch19_13.htm

    0100000 => type:   regular file
    0040000 => type:   directory
    0000400 => owner:  read permission
    0000200 => owner:  write permission
    0000040 => group:  read permission
    0000020 => group:  write permission
    0000004 => others: read permission
    0000002 => others: write permission
    */

    // File or directory?
    // @todo: Add more detailed support for permissions. Currently only takes OWNER into account.
    if (!$object_name) // Root of the bucket
    {
        $mode = octdec('0040777');
    }
    elseif ($file)
    {
        $mode = (str_replace('//', '/', $object_name . '/') === (string) $file->Key) ? octdec('0040777') : octdec('0100777'); // Directory, Owner R/W : Regular File, Owner R/W
    }
    else
    {
        $mode = octdec('0100777');
    }

    // Update stat output
    $out[2] = $out['mode'] = $mode;
    $out[4] = $out['uid'] = (isset($file) ? (string) $file->Owner->ID : 0);
    $out[7] = $out['size'] = (isset($file) ? (string) $file->Size : 0);
    $out[8] = $out['atime'] = (isset($file) ? date('U', strtotime((string) $file->LastModified)) : 0);
    $out[9] = $out['mtime'] = (isset($file) ? date('U', strtotime((string) $file->LastModified)) : 0);
    $out[10] = $out['ctime'] = (isset($file) ? date('U', strtotime((string) $file->LastModified)) : 0);

    return $out;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback