by
8,637 36
0
5
2,491
12
Top 1% !
Popular
Famous
Specified
OpenSource
Popularity: 7531st place

Published on:

No tags for this snippet yet.
Extension.php
LanguagePHP
LicenseMIT_X11
Target Frameworkaws

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/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/5846/Amazon-AWS---PHP--Upload-a-file-taken-fr?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
<?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!"); } ?>
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus