【问题标题】:Upload image using Amazon S3使用 Amazon S3 上传图片
【发布时间】:2010-11-26 00:17:27
【问题描述】:

我需要使用 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";
}
?>

但它给了我这个错误:

<?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>

如何上传文件?

【问题讨论】:

    标签: php amazon-s3 amazon-web-services


    【解决方案1】:

    您正在使用POST 方法(这是PHP 的默认设置)来提交数据。大多数 Web 应用程序都区分动词 GET、PUT 和 POST(参见 W3 RFC on Verbs)。

    S3 希望您使用&lt;AllowedMethod&gt;PUT&lt;/AllowedMethod&gt; 作为方法。 move_uploaded_file 无法做到这一点。在你开始编写执行 PUT 请求的代码之前,也许你应该看看一些 PHP S3 libs。

    【讨论】:

      【解决方案2】:

      试试 Zend Framework,有一个很棒的类 (Zend_Service_Amazon_S3) 可以处理您所有的 S3 麻烦。

      http://framework.zend.com

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

      【讨论】:

        猜你喜欢
        • 2015-08-24
        • 2019-05-15
        • 1970-01-01
        • 2015-06-20
        • 2017-11-04
        • 1970-01-01
        • 1970-01-01
        • 2019-09-20
        • 2011-12-21
        相关资源
        最近更新 更多