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" ?>
<Error>
<Code>MethodNotAllowe</Code>
<Message>The specified method is not allowed against this resource.</Message>
<ResourceType>OBJECT</ResourceType>
<Method>POST</Method>
....
<AllowedMethod>PUT</AllowedMethod>
....
</Error>
How can I upload a file?
You are using the POST method (which is PHP defaults) to submit the data. Most webapplications differenciate between the verbs GET, PUT and POST (see W3 RFC on Verbs).
S3 wants you to use <AllowedMethod>PUT</AllowedMethod> as the method. move_uploaded_file isn't able to do that. Before you start writing code for doing PUT requests, maybe you should take a look at some PHP S3 libs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With