working on it ...

Filters

Explore Public Snippets

Sort by

Found 13 snippets

    public by mporru @ Amazon_AWS_PHP_API  3895  1  5  1

    Amazon AWS - PHP: Generate public download URL

    This snippet demonstrates how to generate a public download URL for a file stored in your S3 Bucket. Target file must have ACL public permissions set. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    <?php
    require_once('sdk.class.php');
    $s3 = new AmazonS3();
    
    $fileName = 'LighthouseNew.jpg';
    $bucketName = 'myBucketName';
    
    $url = $s3->get_object_url($bucketName, $fileName);
    
    echo("Download url: <a href=\"$url\">$url</a>\n");
    ?>

    public by mporru @ Amazon_AWS_PHP_API  2946  0  5  0

    Amazon AWS - PHP: Create a new text file inside a bucket.

    This snippet demonstrates how to use the create_object API. In this case, we create a new text file, filling it up with some text. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    $s3 = new AmazonS3();
    // Create Object is pretty self explanatory:
    // Arg 1: The bucket where your file will be created.
    // Arg 2: The name of your file.
    // Arg 3: An array of Options.
    //        In this case we're specifying the &quot;body&quot; option
    //        and the ACL setting to allow this file to be read by anyone.
    $response = $s3->create_object('MyBucketName', 'newtextfile.txt', array(
    'body' => 'Hello world. Nice to meet you.',
    'acl'=>AmazonS3::ACL_PUBLIC,
    ));
    if ((int) $response->isOK()) echo 'I Created a File!';
    ?>

    public by mporru @ Amazon_AWS_PHP_API  2698  0  5  0

    Installing the PHP SDK

    Actually, this is not a snippet, just some simple instructions on how to setup the PHP SDK.
    Prerequisites: 
    Apache HTTP Server (or any other suitable web server)
    PHP with curl library
    A valid Amazon AWS account
    
    - Download the SDK from here:
    http://pear.amazonwebservices.com/get/sdk-latest.zip
    
    - Extract the zip file in the root of your web server application.
    - Rename the file config-sample.inc.php to config.inc.php
    - Edit the file config.inc.php putting your key and secret
    To obtain those values, log-in to your AWS management console.
    Click "Account", then "Security Credentials".
    Scroll down to find your AWS Key and Secret Key. 
    
    - Write any PHP script, including the SDK at the very beginning of your application:
    <?php
    require_once 'sdk.class.php';
    // ...
    // make any API call
    // ...
    ?>

    public by mporru @ Amazon_AWS_PHP_API  133738  0  5  0

    Amazon AWS - PHP: Create a new Bucket

    This snippet demonstrates how to create a new Amazon S3 Bucket. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    
    // Create the s3 Object from the SDK
    $s3 = new AmazonS3();
    // Run the Method: Create Bucket.
    // Arg 1: 'my-unique-bucket-name' is the name of your new bucket.
    // Arg 2: The geographical region where your data will be stored.
    // Arg 3: Tells Amazon to make your files readable by anyone like regular files hosted on a web server.
    $response = $s3->create_bucket('my-unique-bucket-name', AmazonS3::REGION_US_E1, AmazonS3::ACL_PUBLIC);
    // The response comes back as a Simple XML Object
    // In this case we just want to know if everything was okay.
    // If not, report the message from the XML response.
    if ((int) $response->isOK()) {
        echo 'Created Bucket';
    } else {
        echo (string) $response->body->Message;
    }
    
    ?>

    public by mporru @ Amazon_AWS_PHP_API  1677  0  5  0

    Amazon AWS - PHP: List your Buckets

    This snippet demonstrates how to list all your Amazon S3 Buckets. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    
    // Create the s3 Object from the SDK
    $s3 = new AmazonS3();
    $response = $s3->list_buckets();
    foreach ($response->body->Buckets[0] as $bucket) {
        echo ((string) $bucket->Name)."<br />";
    }
    ?>

    public by mporru @ Amazon_AWS_PHP_API  2490  12  5  0

    Amazon AWS - PHP: Upload a file taken from an external site

    This snippet demonstrates how to upload a file to a S3 Bucket, taking it form a url. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    $s3 = new AmazonS3();
    // Create Object is pretty self explanatory:
    // Arg 1: The bucket where your file will be created.
    // Arg 2: The name of your file.
    // Arg 3: An array of Options.
    //        In this case we're specifying the &quot;body&quot; option (opening a file from the web),
    //        we're setting the contentType of the file so browsers know its an image,
    //        and we're setting the ACL setting to allow this file to be read by anyone.
    $response=$s3->create_object('myBucketName', 'os_logo.png', array('body'=>file_get_contents('http://www.opensociety.it/wp-content/uploads/2012/12/header_OS.png'), 'content_type'=>'image/gif', 'acl'=>AmazonS3::ACL_PUBLIC));
    // Check if everything is okay.
    if ($response->isOK()) {
    	echo("File uploaded correctly");
    } else {
    	echo("There was an error uploading the file!");
    }
    ?>

    public by mporru @ Amazon_AWS_PHP_API  2711  18  5  0

    Amazon AWS - PHP: Download file to browser

    This snippet demonstrates how to download a file stored in your S3 Bucket to your browser. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    <?php
    require_once('sdk.class.php');
    $s3 = new AmazonS3();
    
    $fileName = 'LighthouseNew.jpg';
    $bucketName = 'myBucketName';
    
    $obj = $s3->get_object($bucketName, $fileName);
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=$fileName;");
    
    echo $obj->body;
    ?>

    public by mporru @ Amazon_AWS_PHP_API  210427  0  5  0

    Amazon AWS - PHP: Upload a File taking it from your server

    This snippet demonstrates how to upload a file to a S3 Bucket, taking it form a your server. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    $s3 = new AmazonS3();
    // Create Object is pretty self explanatory:
    // Arg 1: The bucket where your file will be created.
    // Arg 2: The name of your file.
    // Arg 3: An array of Options.
    //        In this case we're specifying the &quot;fileUpload&quot; option (a file on your server)
    //        and the ACL setting to allow this file to be read by anyone.
    $response=$s3->create_object('myBucketName', 'LighthouseNew.jpg', 
    array('fileUpload'=>'./Lighthouse.jpg', 'acl'=>AmazonS3::ACL_PUBLIC));
    // Check if everything is okay.
    if ($response->isOK()) {
    	echo("File uploaded correctly");
    } else {
    	echo("There was an error uploading the file!");
    }
    ?>

    public by mporru @ Amazon_AWS_PHP_API  320987  0  5  0

    Amazon AWS - PHP: Generate signed expiring download URL

    This snippet demonstrates how to generate a download URL for a file stored in your S3 Bucket. This will work for all files, even ACL private files. Download URL will be active for the specified time. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    <?php
    require_once('sdk.class.php');
    $s3 = new AmazonS3();
    
    $fileName = 'test1.txt';
    $bucketName = 'myBucketName';
    
    $url = $s3->get_object_url($bucketName, $fileName, '1 hour');
    
    echo("Download url: <a href=\"$url\">$url</a>\n");
    ?>

    public by mporru @ Amazon_AWS_PHP_API  2454  0  5  0

    Amazon AWS - PHP: Modify ACL permissions

    This snippet demonstrates how to modify ACL permissions for a file in S3 bucket. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    <?php
    require_once('sdk.class.php');
    $s3 = new AmazonS3();
    
    $bucketName = 'myBucketName';
    $fileName = 'test1.txt';
    
    $response = $s3->set_object_acl($bucketName, $fileName, AmazonS3::ACL_PRIVATE);
    
    if ($response->isOK()) {
    	echo("Permissions changed correctly");
    } else {
    	echo("There was an error changing the permissions for file $fileName!");
    }
    ?>
    • Public Snippets
    • Channels Snippets