8

This is my first PHP project, so I really don't know PHP at all.

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.

Now I just get the following error returned by the putObject function:

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

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.

The PHP code that I have is:

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;
Dave Long
  • 9,569
  • 14
  • 59
  • 89

1 Answers1

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.

bdonlan
  • 224,562
  • 31
  • 268
  • 324
  • Thanks. I changed the timezone, but didn't think to look at the actual time. It was about 18 minutes off. – Dave Long Oct 13 '11 at 04:07
  • I'm working off a localhost MAMP installation. I had uploads to S3 working this morning, put my computer to sleep for the rest of the day and this started happening. Restarting apache didn't work, but restarting my computer did. – Brad G Jan 18 '13 at 02:46