Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PHP to upload to Amazon S3

I've spent the last few hours following tutorials for implementing file uploads to Amazon S3 using php. I uploaded the most recent version of Donovan Schönknecht's S3 class to my server (as S3.php) and I am trying to use the following code to test upload capability. I know this code will work because I've seen numerous examples in action.

<?php

require('S3.php');

$s3 = new S3('KEY', 'SECRET KEY');

//insert into s3
$new_name = time() . '.txt';

S3::putObject(
'upload-me.txt',
'bucketName',
$new_name,
S3::ACL_PUBLIC_READ,
array(),
array(),
S3::STORAGE_CLASS_RRS

);

?>

I get an error 500 server error when I attempt to load this page. Additionally, every other reputable tutorial of this nature has given me the same error 500.

I verified that my key and secret key are valid by connecting to S3 with Cyberduck.

Does anyone have a clue as to what I could be doing incorrectly?

Thanks,

Sean

like image 913
Sean Avatar asked Apr 27 '13 20:04

Sean


2 Answers

As it turns out, I was missing the cURL extension for PHP and this was causing an issue as the S3 class I was using required the use of cURL. All is working now.

like image 153
Sean Avatar answered Oct 10 '22 11:10

Sean


You should also consider using the official AWS SDK for PHP. Examples for using S3 with the SDK can be found in their S3 user guide.

like image 28
Jeremy Lindblom Avatar answered Oct 10 '22 11:10

Jeremy Lindblom