无法使用模式 r 打开:fopen():AWS Elastic Beanstalk [英] Unable to open using mode r: fopen(): AWS Elastic Beanstalk

查看:27
本文介绍了无法使用模式 r 打开:fopen():AWS Elastic Beanstalk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Error:Unable to open using mode r: fopen(): Filename cannot be empty I keep getting this error when I try to upload larger files (more than 5MB). I have uploaded the PHP app to AWS Elastic Beanstalk and I upload the files to AWS S3. I don't even have fopen() in the code.

Alson 当我使用 XAMPP 测试网站时,我没有收到此错误.

Alson when I test the site using XAMPP I don't get this error.

这是我用来上传文件到 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");

  }
?>

推荐答案

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

Try to increase the POST_MAX_SIZE and UPLOAD_MAX_FILESIZE values in your php.ini!

这篇关于无法使用模式 r 打开:fopen():AWS Elastic Beanstalk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆