阿里雲開放存儲服務 OSS:用於存儲圖片、apk等靜態資源,使用阿里雲帶寬,不占用開發者服務器帶寬。
阿里雲官方PHP SDK:
http://aliyun.com/product/oss/#help
對於這種第三方庫,PHP官方稱之為PEAR,需要按照PEAR標准開發(標准URI)。
PEAR的優勢:一鍵安裝到php/lib/php目錄,require即可使用,很方便。
由於阿里雲官方PHP SDK沒按照PEAR標准開發,使用不方便,所以我開發了一個,安裝步驟如下:
pear channel-discover sinkcup.github.io/pear pear install sinkcup/HTTP pear install sinkcup/Services_Aliyun_OSS
使用步驟:
1、到阿里雲注冊一個帳號,開通OSS,創建一個bucket空間。
2、demo(參考https://github.com/sinkcup/Services_Aliyun_OSS/blob/0.0.1/tests/Services/Aliyun/OSSTest.php):
<?php require Services/Aliyun/OSS.php; $conf = array( 'accessKeyId' => 'foo', 'accessKeySecret' => 'bar', ); $c = new Services_Aliyun_OSS('com-example-dl', $conf); $headers = array( 'Content-Type' => 'image/jpeg', ); $r = $c->put('/home/u1/2.jpg', '/2.jpg', $headers ); var_dump($r); $this->assertArrayHasKey('internet', $r); ?>