Hi everyone
I have been working closely with amazon s3 over the last couple off days and i am starting to find how useful it is to keep everything files folders onlinne.
I looking for a upload solution for amazon for a while. I found a great solution Amazon S3 Class this has great documentation.
If you download their class you can find a Amazon s3 upload solution.
Here is an example.
<?php
S3::setAuth(awsAccessKey, awsSecretKey);
$bucket = "upload-bucket";
$path = "myfiles/"; // Can be empty ""
$lifetime = 3600; // Period for which the parameters are valid
$maxFileSize = (1024 * 1024 * 50); // 50 MB
$metaHeaders = array("uid" => 123);
$requestHeaders = array(
"Content-Type" => "application/octet-stream",
"Content-Disposition" => 'attachment; filename=${filename}'
);
$params = S3::getHttpUploadPostParams(
$bucket,
$path,
S3::ACL_PUBLIC_READ,
$lifetime,
$maxFileSize,
201, // Or a URL to redirect to on success
$metaHeaders,
$requestHeaders,
false // False since we're not using flash
);
$uploadURL = "https://{$bucket}.s3.amazonaws.com/";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>S3 Form Upload</title>
</head>
<body>
<form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
<?php
foreach ($params as $p => $v)
echo " <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
?>
<input type="file" name="file" /> <input type="submit" value="Upload" />
</form>
</body>
</html>
This works great but i always have an issue with leaving a user with no reference off upload progress i have the assumption that with large downloads people will natural asume that the process has stopped or broke, and close or refresh the browser.
So from this solution i set about looking for a direct upload with a progress bar. This wasnt easy i spent a long time goggling etc, eventually i found uploadify which i thought would be a great soultion but this failed for me and i am still work on this so wait for the post.
Things i found when working with amazon when uploading a file it requires upload paramaters to be sent to amazon to allow for a secure upload. As you can see from the example above.
Please view the documentation here
http://docs.amazonwebservices.com/AmazonS3/latest/dev/
http://doc.s3.amazonaws.com/proposals/post.html
Ok so enough text this is what you are looking for the code.
Download the code and then change the information shown below.
// CHANGE EVERYTHING BELOW define(AWS_ACCESS_KEY_ID,'YOUR AMAZON KEY'); define(AWS_SECRET_ACCESS_KEY,'YOU SECRET AMAZON KEY'); $S3_BUCKET = 'ENTER YOUR BUCKET'; $SUCCESS_REDIRECT = "CAN PUT A SUCCESS URL HERE IF YOU WANT"; $SWFRoot = "PUT IN THE ROOT URL TO YOUR WEBSITE";
Please make sure you upload this to the amazon bucket where you wish the files to upload into.
Call it crossdomain.xml and add the following.
<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <allow-access-from domain="*" secure="false" /> </cross-domain-policy>
Let me know how you get on.