Something I threw together in about 6 hours… it’s a good start (and its workable) but needs a lot of work (polish, etc)… but right now there is literally nothing out there even remotely close to this class. So I thought I would share it with the world… Perhaps I’ll setup a project page and put it under subversion if people care to actually contribute.
http://blog.apokalyptik.com/storage3.phps
Update: I’ve put together a “release” of this project. Please visit The Storage3 Interface to Amazons S3 “Simple Storage Service” home page.
Hi there,
Trying to use your class (I grabbed the 1.0 off your dev site), but it's bombing out with:
InvalidSecurity: The provided security credentials are not valid.
I can list my buckets just fine, but I'm trying to use putFile/mkFile and neither wants to cooperate. Any ideas?
Did you modify HTTP_Request.php? The only difference between the version in PEAR and the one bundled with your app is the following line-set:
ORIGINAL:
(HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_postData) && empty($this->_postFiles))) {
YOURS:
(HTTP_REQUEST_METHOD_POST == $this->_method && empty($this->_postData) && empty($this->_postFiles))) {
There's nothing wrong with making these kinds of modifications so long as you warn people who want to use your class with their own pear-libs. Anyways, now that I've updated my HTTP_Request.php with that changed line it works great. Thanks for creating this.
Here's my contribution for you:
function setACL($s3bucket, $s3file, $shorthand="public-read") {
$s3file = $s3file . "?acl";
$req =& new HTTP_Request($this->accessUrl . $s3bucket .'/'. $s3file);
//echo $this->accessUrl . $s3bucket .'/'. $s3file;
$req->setMethod("PUT");
$httpDate = gmdate(DATE_RFC822);
// Mandatory headers
$tosign[]="PUT";
// TODO: Impliment md5 checksums
$tosign[]="";
$tosign[]="";
$tosign[]=$httpDate;
$tosign[]="x-amz-acl:" . $shorthand;
$tosign[]='/'.$s3bucket.'/'.$s3file;
$req->addHeader("Date", $httpDate);
$this->authUnSigned="AWS {$this->accessKeyId}:".implode("n", $tosign);
$authSigned="AWS {$this->accessKeyId}:".$this->strSign(implode("n", $tosign));
$req->addHeader("Authorization", $authSigned);
$req->addHeader("x-amz-acl", $shorthand);
$req->sendRequest();
$this->responseStr=$req->getResponseBody();
$this->responseNice=$this->errorTranslate($req->getResponseCode());
if ($this->responseInt != 200) {
$this->_parseErrorStr();
return(FALSE);
} else {
return(TRUE);
}
}
Well since you're moderating comments, go ahead and delete my gripe about HTTP/Request.php. I see that you actually did say you modified it on the project page; completely my mistake. Anyways, feel free to delete all these comments, but setACL is probably worthwhile.
Thanks for you comments, and the additional code! Rare indeed to get code back, and I really appreciate it! I'll probably be implimenting this very soon in a large project, and I'm sure other code changes are coming. I'll be sure to give this guy a look, and to include it in the next "formal" release!
Cheers!
–Apok
Sure, I always appreciate it when people contribute, so I try to when I can. I made another change to the mkFile function that basically takes another argument enabling you to set the ACL at time of upload. It's pretty easy to extrapolate from the setACL function how to go about modifying mkFile.
While we're at it, I just implemented S3 for serving up my square-thumbnails at http://www.katanapg.com/
Hi there,
I try to run s3test.php on my host and I receive this error
Fatal error: Call to undefined function: simplexml_load_string() in /home/kenvunz/public_html/photocms/s3/Storage3/Storage3.php on line 490
any idea of this problem?
thanks.
no worry, I just figure that out. My host uses old version of PHP.
Hi, I have another problem, and you probably can help
I have 'SignatureDoesNotMatch' message from S3 server. Thought that there is something wrong with my secret code, but then I tried to use another method to put a file (jSh3ll) it's working fine.
Any help would be greatly appreciate !
Hmm… which method(s) are not working, and what parameters are you passing them? as much detail as possible (without giving out your connection codes of course) would help in helping you!
Apok