為七牛雲存儲開發的PHP PEAR 包:Services_Qiniu


七牛雲存儲Qiniu Resource (Cloud) Storage:用於存儲圖片、apk等靜態資源。

優點:

1、使用七牛帶寬和CDN,速度快,不占用開發者服務器。

2、支持圖片任意格式、任意分辨率自動生成,可以用來做圖片服務器。

3、小流量免費:存儲空間 10GB,每月下載流量 10GB,每月 PUT/DELETE 10萬次請求,每月 GET 100萬次請求。當項目發展大時,需要更大流量才需購買。適合互聯網創業者。

4、支持webp,畫質不變,圖片體積大幅度減小,特別適合作移動互聯網app的圖片服務器。

 

比如:

原圖 103KB:http://com-163-sinkcup.qiniudn.com/6ffe255fab20747c8872638870268703

自動生成jpg 79KB:http://com-163-sinkcup.qiniudn.com/6ffe255fab20747c8872638870268703?imageMogr/v2/auto-orient/thumbnail/1366x768/quality/80/format/jpg

自動生成webp 23KB:http://com-163-sinkcup.qiniudn.com/6ffe255fab20747c8872638870268703?imageMogr/v2/auto-orient/thumbnail/1366x768/quality/80/format/webp

 

七牛官方PHP SDK:

http://docs.qiniu.com/php-sdk/v6/index.html

對於這種第三方庫,PHP官方稱之為PEAR,需要按照PEAR標准開發(標准URI)。

PEAR的優勢:一鍵安裝到php/lib/php目錄,require即可使用,很方便。

由於七牛官方PHP SDK沒按照PEAR標准開發,使用不方便,所以我開發了一個,安裝步驟如下:

pear channel-discover sinkcup.github.io/pear
pear install sinkcup/Services_Qiniu

使用步驟:

1、到七牛(http://www.qiniu.com/)注冊一個帳號,創建一個bucket空間。

2、demo(參考https://github.com/sinkcup/php-sdk/blob/pear/tests/Services/Qiniu/RSTest.php):

<?php
$conf = array(
    'accessKey' => 'foo',
    'secretKey' => 'bar',
);
require 'Services/Qiniu/RS.php';
$c = new Services_Qiniu_RS('com-example-img-agc', $conf);
$headers = array(
    'Content-Type' => 'image/jpeg',
);
$r = $c->uploadFile('/home/u1/2.jpg', '/2.jpg', $headers);
var_dump($r);
?>

輸出:

array(1) {
  ["uri"]=>
  string(40) "http://com-163-sinkcup.qiniudn.com/2.jpg"
}

 

七牛官方PHP SDK源代碼:

https://github.com/qiniu/php-sdk

fork以后,我的Services_Qiniu源代碼:

https://github.com/sinkcup/php-sdk/tree/pear

PEAR頻道:

http://sinkcup.github.io/pear/


免責聲明!

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



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