照片未使用php上传到s3存储桶

时间:2019-10-04 09:42:37

标签: php amazon-s3 aws-sdk

我正在尝试通过ec2实例将图像上传到s3存储桶。但是图像未上传到s3。我可以验证它们是否已上传到ec2实例。上传到s3时出现问题。我意识到上传功能不起作用,但是我不确定。自两天以来,我一直在努力解决这一问题。任何帮助将不胜感激。

EC2实例是一台Linux计算机。它已经安装了cURL和PHP-cURL。图像将保存在文件夹“上载”中。通过解压缩来安装Amazon SDK。

<?php
//use Aws\S3\ObjectUploader;
use Aws\S3\MultipartUploader;
use Aws\Common\Exception\S3Exception;
use Aws\S3\S3Client;
use Aws\Exception\MultipartUploadException;
require 'aws-autoloader.php';
    $uploaddir = 'uploads/';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
    echo "1";
    $s3_client = new S3Client([
      'profile' => 'default',
      'version' => 'latest',
      'region' => 'ap‐southeast‐2']);
    echo "2";

    $bucketName = 'ramyaassignment1b';
    $key ='a.jpg';

    echo "<p>";

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
      echo "File is valid, and was successfully uploaded.\n";
      echo "3";
      //$uploadfile= dirname(__FILE__).'uploads/a.jpg';
      $uploader = new MultipartUploader( $s3_client, $uploadfile, ['bucket'=>$bucketName, 'key'=>basename($_FILES['userfile']['name'])]);
      //$uploader = new ObjectUploader($s3_client,$bucketName,$key,$uploadfile);
      echo "4";
          try {
            $uploader->upload();
            echo "5";
    //echo "Upload complete: {$result['ObjectURL']}\n";
} catch (MultipartUploadException $e) {
    echo $e->getMessage() . "\n";
    echo "6";
}
    } else {
       echo "Upload failed";
}
    ?>

我看不到任何错误。而且没有文件上传。我可以看到数字4被打印了,但是之后5或6都没有被打印。

0 个答案:

没有答案