This is my first PHP project, so I really don't know PHP at all.
这是我的第一个PHP项目,所以我真的根本不懂PHP。
What I am trying to do is upload a file to an S3 bucket using the PHP S3 class. An example snippet of code was working yesterday, but when I went to start working with it again today, almost the exact same code stopped working.
我想要做的是使用PHP S3类将文件上传到S3存储桶。一个示例代码片段昨天正在运行,但是当我今天再次开始使用它时,几乎完全相同的代码停止工作。
Now I just get the following error returned by the putObject function:
现在我只是得到putObject函数返回的以下错误:
Warning: S3::putObject(): RequestTimeTooSkewed The difference between the request time and the current time is too large. in /vagrant/LifeInYourWay/S3.php on line 222
警告:S3 :: putObject():RequestTimeTooSkewed请求时间和当前时间之间的差异太大。在第222行的/vagrant/LifeInYourWay/S3.php中
I read some places that the server time could be causing the error so I changed my server time to America/New_York but still get the same thing.
我读了一些地方,服务器时间可能导致错误,所以我将服务器时间更改为America / New_York,但仍然得到相同的东西。
The PHP code that I have is:
我的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;
1 个解决方案
#1
16
Your computer's clock or time zone setting is incorrect. Because S3 uses the current time to authenticate requests, if your clock is off by more than 15 minutes, or if your time zone is incorrect (thus leading to a skew of hours), your requests will fail.
您的计算机的时钟或时区设置不正确。因为S3使用当前时间来验证请求,如果您的时钟关闭超过15分钟,或者您的时区不正确(从而导致时间偏差),您的请求将失败。
#1
16
Your computer's clock or time zone setting is incorrect. Because S3 uses the current time to authenticate requests, if your clock is off by more than 15 minutes, or if your time zone is incorrect (thus leading to a skew of hours), your requests will fail.
您的计算机的时钟或时区设置不正确。因为S3使用当前时间来验证请求,如果您的时钟关闭超过15分钟,或者您的时区不正确(从而导致时间偏差),您的请求将失败。