无法使用模式 r 打开:fopen():AWS Elastic Beanstalk

To.*_*. K 3 php amazon-web-services amazon-elastic-beanstalk

错误:无法使用模式 r 打开:fopen():文件名不能为空当我尝试上传更大的文件(超过 5MB)时,我不断收到此错误。我已将 PHP 应用程序上传到 AWS Elastic Beanstalk,并将文件上传到 AWS S3。我什至没有 fopen() 在代码中。

另外,当我使用 XAMPP 测试站点时,我没有收到此错误。

这是我用来将文件上传到 S3 的代码:

<?php

session_start();
require 'vendor/autoload.php';

  use Aws\S3\S3Client;
  use Aws\S3\Exception\S3Exception;

  // AWS Info
  $bucketName = 'tolga20.images';
  $IAM_KEY = '******************';
  $IAM_SECRET = '*************************';

  $feedback = '';
  $unqiue_num = mt_rand(1000, 9999);


  if(isset($_FILES['fileToUpload'])) {

    $user_set_id = $_POST['user_set_id'];



    // Connect to AWS
    try {
      // You may need to change the region. It will say in the URL when the bucket is open
      // and on creation.
      $s3 = S3Client::factory(
        array(
          'credentials' => array(
            'key' => $IAM_KEY,
            'secret' => $IAM_SECRET
          ),
          'version' => 'latest',
          'region'  => 'eu-west-2'
        )
      );
    } catch (Exception $e) {
      // We use a die, so if this fails. It stops here. Typically this is a REST call so this would
      // return a json object.
      die("Error: " . $e->getMessage());
    }

    $temp_name = explode(".", $_FILES["fileToUpload"]["name"]);
    $newfilename = $unqiue_num . "-" . $user_set_id . '.' . end($temp_name);

    // For this, I would generate a unqiue random string for the key name. But you can do whatever.
    $keyName = 'images/' . basename($newfilename);
    $pathInS3 = 'https://s3.eu-west-2.amazonaws.com/' . $bucketName . '/' . $keyName;

    // Add it to S3
    try {
      // Uploaded:
      $file = $_FILES["fileToUpload"]['tmp_name'];
      $s3->putObject(
        array(
          'Bucket'=>$bucketName,
          'Key' =>  $keyName,
          'SourceFile' => $file,
          'StorageClass' => 'REDUCED_REDUNDANCY'
        )
      );
    } catch (S3Exception $e) {
      die('Error:' . $e->getMessage());
    } catch (Exception $e) {
      die('Error:' . $e->getMessage());
    }
    //$feedback = 'File uploaded! Custom name: ' . '<b><i>' . $newfilename;
    $_SESSION['newfilename'] = $newfilename;
    header("Location: next.php");

  }
?>
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试增加 php.ini 中的 POST_MAX_SIZE 和 UPLOAD_MAX_FILESIZE 值!