Upload Image Using Amazon S3

I need to upload a given image using Amazon S3

I have this PHP:

$uploaddir = 'images/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "Data Uploaded Successfully";
} else {
    echo "ERROR";


but it gives me this error:

<?xml version="1.0" encoding="UTF-8" ?>
    <Message>The specified method is not allowed against this resource.</Message>


How do I upload a file?


source to share

2 answers

You are using a method POST

(which is the default PHP standard) to send data. Most web applications differentiate between verbs GET


and POST

(see the W3 RFC on verbs ).

S3 wants to use it <AllowedMethod>PUT</AllowedMethod>

as a method. move_uploaded_file cannot do this. Before you start writing code to make PUT requests, you might want to take a look at some PHP S3 libs .



Try Zend Framework, there is a great class (Zend_Service_Amazon_S3) to handle all your S3 issues.


require_once 'Zend/Service/Amazon/S3.php';
$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);
$s3->putObject("my-own-bucket/myobject", $file);




All Articles