gpt4 book ai didi

php - 使用 PHP S3 类的 RequestTimeTooSkewed 错误

转载 作者:可可西里 更新时间:2023-11-01 12:29:56 25 4
gpt4 key购买 nike

这是我的第一个 PHP 项目,所以我真的完全不懂 PHP。

我想做的是使用 PHP S3 类将文件上传到 S3 存储桶。一个示例代码片段昨天可以正常工作,但当我今天再次开始使用它时,几乎完全相同的代码停止工作了。

现在我只收到 putObject 函数返回的以下错误:

警告:S3::putObject(): RequestTimeTooSkewed 请求时间与当前时间之间的差异太大。在/vagrant/LifeInYourWay/S3.php 第 222 行

我在一些地方读到服务器时间可能导致错误,所以我将服务器时间更改为 America/New_York,但仍然得到同样的结果。

我的 PHP 代码是:

if(!class_exists('S3')) require_once('S3.php');

// AWS access
if(!defined('awsAccessKey')) define('awsAccessKey', '******');
if(!defined('awsSecretKey')) define('awsSecretKey', '******');

$s3 = new S3(awsAccessKey, awsSecretKey);

$imageName = $_FILES['imageFile']['name'];
$imageTempName = $_FILES['imageFile']['tmp_name'];
$imageLink = $_POST['imageLink'];

if(!strlen($imageLink) || $imageLink == 'http://'){
//create a new bucket
$s3->putBucket("widget-images", S3::ACL_PUBLIC_READ);

//move the file
$put = $s3->putObject($s3->inputFile($imageTempName), "widget-images", $imageName, S3::ACL_PUBLIC_READ);
if($put){
var_dump($put);
$imageUploaded = true;
}else{
$imageUploaded = false;
}
echo($imageUploaded);
}else $image = $imageLink;

最佳答案

您计算机的时钟或时区设置不正确。由于 S3 使用当前时间对请求进行身份验证,如果您的时钟偏差超过 15 分钟,或者如果您的时区不正确(从而导致时间偏差),您的请求将失败。

关于php - 使用 PHP S3 类的 RequestTimeTooSkewed 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7749156/

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