photos not uploading to s3 bucket using php

二次信任 提交于 2020-01-24 00:32:14

问题


I am trying to upload images to s3 bucket via ec2 instance. But the images are not being uploaded to s3. I could verify that they are getting uploaded to ec2 instance. there is some problem in uploading to s3. I realised that upload function is not working, but I am not sure. I have been trying to solve this since two days. Any help would be really appreciated.

EC2 instance is a linux machine. it has cURL and PHP-cURL installed. images are getting saved in the folder "uploads". Amazon SDK are installed by unzipping them.

<?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";
}
    ?>

I cannot see any error. And no files are getting uploaded. I could see number 4 getting printed, but after that both 5 or 6 is not getting printed.

来源:https://stackoverflow.com/questions/58233820/photos-not-uploading-to-s3-bucket-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!