Trying to write my own class since I only need "putobject" functionality. I can't get this to work to save my life.
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
class s3{
var $__ak = 'accessKey';
var $__sk = 'shareKey';
var $__bucket = 'bucket';
var $__headers = false;
var $__content = false;
var $__verb = false;
var $__data = false;
function __getSignature(){
$query = $this->__verb."
".$this->__headers['Content-MD5']."
".$this->__headers['Content-Type']."
".$this->__headers['Date']."
".$this->__data;
return 'AWS '.$this->__ak.':'.base64_encode(hash_hmac('sha1',$query,$this->__sk,true));
}
function __returnHeaders(){
foreach($this->__headers as $k=>$v) $temp[] = $k.': '.$v;
return $temp?$temp:false;
}
function __putObject($input){
$this->__verb = 'PUT';
$this->__data = $input;
$this->__headers['Host'] = $this->__bucket.'.s3.amazonaws.com';
$this->__headers['Date'] = gmdate('D, d M Y H:i:s O');
$this->__headers['Authorization'] = $this->__getSignature();
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'S3/php');
curl_setopt($ch, CURLOPT_URL, $this->__headers['Host']);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->__returnHeaders());
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, '@'.$input);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
}
}
$s = new s3;
$s->__putObject('/image.jpg');