Home  >  Article  >  Backend Development  >  PHP PEAR package developed for Qiniu Cloud Storage: Services_Qiniu_PHP Tutorial

PHP PEAR package developed for Qiniu Cloud Storage: Services_Qiniu_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:15:131019browse

Qiniu Resource (Cloud) Storage: used to store static resources such as pictures and apk.

Advantages:

1. Using Qiniu bandwidth and CDN, it is fast and does not occupy the developer server.

2. Supports automatic generation of pictures in any format and resolution, and can be used as a picture server.

3. Small traffic is free: 10GB storage space, 10GB monthly download traffic, 100,000 PUT/DELETE requests per month, and 1 million GET requests per month. When the project develops, it needs to be purchased if it needs more traffic. Suitable for Internet entrepreneurs.

4. Support webp, the image quality remains unchanged, and the image size is greatly reduced. It is especially suitable for use as a picture server for mobile Internet apps.

For example:

Original image 103KB: http://com-163-sinkcup.qiniudn.com/6ffe255fab20747c8872638870268703

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

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

Qiniu official PHP SDK:

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

For this third-party library, PHP officially calls it PEAR and needs to be developed according to the PEAR standard (standard URI).

Advantages of PEAR: One-click installation to the php/lib/php directory, require to use, very convenient.

Since Qiniu’s official PHP SDK was not developed in accordance with PEAR standards and is inconvenient to use, I developed one. The installation steps are as follows:

pear channel-discover sinkcup.github.io/<span pear
pear install sinkcup</span>/Services_Qiniu

Usage steps:

1. Register an account at Qiniu (http://www.qiniu.com/) and create a bucket space.

2. Demo (refer to https://github.com/sinkcup/php-sdk/blob/pear/tests/Services/Qiniu/RSTest.php):

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

Output:

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

Qiniu official PHP SDK source code:

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

After fork, my Services_Qiniu source code:

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

PEAR Channel:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440213.htmlTechArticleQiniu Cloud Storage Qiniu Resource (Cloud) Storage: used to store static resources such as pictures and apk. Advantages: 1. Using Qiniu bandwidth and CDN, it is fast and does not occupy the developer server. 2. Support...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn