• <tfoot id='zHjOs'></tfoot>

          <bdo id='zHjOs'></bdo><ul id='zHjOs'></ul>
        <i id='zHjOs'><tr id='zHjOs'><dt id='zHjOs'><q id='zHjOs'><span id='zHjOs'><b id='zHjOs'><form id='zHjOs'><ins id='zHjOs'></ins><ul id='zHjOs'></ul><sub id='zHjOs'></sub></form><legend id='zHjOs'></legend><bdo id='zHjOs'><pre id='zHjOs'><center id='zHjOs'></center></pre></bdo></b><th id='zHjOs'></th></span></q></dt></tr></i><div id='zHjOs'><tfoot id='zHjOs'></tfoot><dl id='zHjOs'><fieldset id='zHjOs'></fieldset></dl></div>

        <small id='zHjOs'></small><noframes id='zHjOs'>

      1. <legend id='zHjOs'><style id='zHjOs'><dir id='zHjOs'><q id='zHjOs'></q></dir></style></legend>

        使用 PHP SDK 在亚马逊 S3 上上传文件

        Upload file on amazon S3 with PHP SDK(使用 PHP SDK 在亚马逊 S3 上上传文件)
          <bdo id='Qflwy'></bdo><ul id='Qflwy'></ul>
                <tbody id='Qflwy'></tbody>
              <tfoot id='Qflwy'></tfoot>

              • <legend id='Qflwy'><style id='Qflwy'><dir id='Qflwy'><q id='Qflwy'></q></dir></style></legend>

                <small id='Qflwy'></small><noframes id='Qflwy'>

                <i id='Qflwy'><tr id='Qflwy'><dt id='Qflwy'><q id='Qflwy'><span id='Qflwy'><b id='Qflwy'><form id='Qflwy'><ins id='Qflwy'></ins><ul id='Qflwy'></ul><sub id='Qflwy'></sub></form><legend id='Qflwy'></legend><bdo id='Qflwy'><pre id='Qflwy'><center id='Qflwy'></center></pre></bdo></b><th id='Qflwy'></th></span></q></dt></tr></i><div id='Qflwy'><tfoot id='Qflwy'></tfoot><dl id='Qflwy'><fieldset id='Qflwy'></fieldset></dl></div>

                  本文介绍了使用 PHP SDK 在亚马逊 S3 上上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试通过他们的 PHP SDK 在我的亚马逊 S3 上上传图片.所以我做了一个小脚本来做到这一点.但是,我的脚本不起作用,我的异常也没有给我发回任何错误消息.

                  I'm trying to upload a picture on my amazon S3 via their PHP SDK. So I made a little script to do so. However, my script doesn't work and my exception doesn't send me back any error message.

                  我是 AWS 新手,感谢您的帮助.

                  I'm new with AWS thank you for your help.

                  代码如下:

                  配置.php

                  <?php 
                  
                  return array(
                  'includes' => array('_aws'),
                  'services' => array(
                    'default_settings' => array(
                        'params' => array(
                            'key'    => 'PUBLICKEY',
                            'secret' => 'PRIVATEKEY',
                            'region' => 'eu-west-1'
                        )
                      )
                    )
                  );
                  
                  ?>
                  

                  索引.php

                   <?php
                  
                  
                  //Installing AWS SDK via phar
                  require 'aws.phar';
                  
                  use AwsS3S3Client;
                  use AwsS3ExceptionS3Exception;
                  
                  $bucket = 'infact';
                  $keyname = 'myImage';
                  
                  // $filepath should be absolute path to a file on disk                      
                  $filepath = 'image.jpg';
                  
                  // Instantiate the client.
                  $s3 = S3Client::factory('config.php');
                  
                  // Upload a file.
                  try {
                  
                  $result = $s3->putObject(array(
                      'Bucket'       => $bucket,
                      'Key'          => $keyname,
                      'SourceFile'   => $filePath,
                      'ContentType'  => 'text/plain',
                      'ACL'          => 'public-read',
                      'StorageClass' => 'REDUCED_REDUNDANCY'
                  ));
                  
                   // Print the URL to the object.
                      echo $result['ObjectURL'] . "
                  ";
                  } catch (S3Exception $e) {
                      echo $e->getMessage() . "
                  ";
                  }
                  
                  ?>
                  

                  我现在正在使用此代码,但它仍然无法正常工作.我什至没有错误或异常消息.

                  EDIT : I'm now using this code but its still not working. I don't even have error or exception message.

                      <?php
                  
                  require 'aws.phar';
                  
                  use AwsS3S3Client;
                  use AwsS3ExceptionS3Exception;
                  
                  $bucket = 'infactr';
                  $keyname = 'sample';
                  // $filepath should be absolute path to a file on disk                      
                  $filepath = 'image.jpg';
                  
                  // Instantiate the client.
                  $s3 = S3Client::factory(array(
                      'key'    => 'key',
                      'secret' => 'privatekey',
                      'region' => 'eu-west-1'
                  
                      ));
                  
                  try {
                      // Upload data.
                      $result = $s3->putObject(array(
                          'Bucket' => $bucket,
                          'Key'    => $keyname,
                          'SourceFile'   => $filePath,
                          'ACL'    => 'public-read',
                          'ContentType' => 'image/jpeg'
                      ));
                  
                      // Print the URL to the object.
                      echo $result['ObjectURL'] . "
                  ";
                  } catch (S3Exception $e) {
                      echo $e->getMessage() . "
                  ";
                  }
                  
                  ?>
                  

                  推荐答案

                  尝试这样的事情(来自 AWS 文档):

                  Try something like this (from the AWS docs):

                  <?php
                  
                  require 'aws.phar';
                  
                  use AwsS3S3Client;
                  use AwsS3ExceptionS3Exception;
                  
                  $bucket = '<your bucket name>';
                  $keyname = 'sample';
                  // $filepath should be absolute path to a file on disk                      
                  $filepath = '/path/to/image.jpg';
                  
                  // Instantiate the client.
                  $s3 = S3Client::factory(array(
                      'key'    => 'your AWS access key',
                      'secret' => 'your AWS secret access key'
                  ));
                  
                  try {
                      // Upload data.
                      $result = $s3->putObject(array(
                          'Bucket' => $bucket,
                          'Key'    => $keyname,
                          'SourceFile'   => $filepath,
                          'ACL'    => 'public-read'
                      ));
                  
                  
                  
                      // Print the URL to the object.
                      echo $result['ObjectURL'] . "
                  ";
                  } catch (S3Exception $e) {
                      echo $e->getMessage() . "
                  ";
                  }
                  
                  ?>
                  

                  只要您拥有正确的凭据,它就可以正常工作.请记住,密钥名称是您在 S3 中文件的名称,因此如果您想让您的密钥与您的文件具有相同的名称,您必须执行以下操作:$keyname = 'image.jpg'; .此外,jpg 通常不是 plain/text 文件类型,您可以省略该 Content-type 字段,或者您可以简单地指定:image/jpeg

                  It works fine for me as long as you have the right credentials. Keep in mind that the key name is the name of your file in S3 so if you want to have your key have the same name of your file you have to do something like: $keyname = 'image.jpg'; . Also, a jpg is generally not a plain/text file type, you can ommit that Content-type field or you can just simply specify: image/jpeg

                  这篇关于使用 PHP SDK 在亚马逊 S3 上上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

                    • <i id='bgiw0'><tr id='bgiw0'><dt id='bgiw0'><q id='bgiw0'><span id='bgiw0'><b id='bgiw0'><form id='bgiw0'><ins id='bgiw0'></ins><ul id='bgiw0'></ul><sub id='bgiw0'></sub></form><legend id='bgiw0'></legend><bdo id='bgiw0'><pre id='bgiw0'><center id='bgiw0'></center></pre></bdo></b><th id='bgiw0'></th></span></q></dt></tr></i><div id='bgiw0'><tfoot id='bgiw0'></tfoot><dl id='bgiw0'><fieldset id='bgiw0'></fieldset></dl></div>

                        <tfoot id='bgiw0'></tfoot>
                        1. <small id='bgiw0'></small><noframes id='bgiw0'>

                            <bdo id='bgiw0'></bdo><ul id='bgiw0'></ul>
                              <tbody id='bgiw0'></tbody>
                            <legend id='bgiw0'><style id='bgiw0'><dir id='bgiw0'><q id='bgiw0'></q></dir></style></legend>