gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:04:43 25 4
gpt4 key购买 nike

Error:Unable to open using mode r: fopen(): Filename cannot be empty 当我尝试上传较大的文件(超过 5MB)时,我不断收到此错误。我已将 PHP 应用程序上传到 AWS Elastic Beanstalk,并将文件上传到 AWS S3。我的代码中甚至没有 fopen() 。

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

这是我用来将文件上传到 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 值!

关于php - 无法使用模式 r : fopen(): AWS Elastic Beanstalk 打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45663757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com