為阿里雲存儲開發的PHP PEAR 包:Services_Aliyun_OSS


阿里雲開放存儲服務 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);
?>

 

項目代碼:https://github.com/sinkcup/Services_Aliyun_OSS

PEAR頻道:http://sinkcup.github.io/pear/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM