使用Amazon S3上传图片 [英] Upload image using Amazon S3

查看:1266
本文介绍了使用Amazon S3上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要上传使用给定的图像的Amazon S3

I need to upload a given image using Amazon S3

我有这个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?

推荐答案

正在使用 POST 的方法(这是PHP的默认值),以提交数据。大多数web应用的动词之间differenciate GET PUT POST (见动词 W3 RFC)。

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要你使用&LT; AllowedMethod&GT; PUT&LT; / AllowedMethod&GT; 的方法。 move_uploaded_file是不是能够做到这一点。在您开始编写code做PUT请求,也许你应该看看一些的 PHP S3库的。

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.

这篇关于使用Amazon S3上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆