Home >Backend Development >PHP Tutorial >PHP PEAR package developed for Alibaba Cloud Storage: Services_Aliyun_OSS_PHP Tutorial
Alibaba Cloud Open Storage Service OSS: used to store static resources such as images and APKs, using Alibaba Cloud bandwidth and not occupying developer server bandwidth.
Alibaba Cloud official PHP SDK:
http://aliyun.com/product/oss/#help
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 Alibaba Cloud’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 </span><span install</span> sinkcup/<span HTTP pear </span><span install</span> sinkcup/Services_Aliyun_OSS
Usage steps:
1. Register an account on Alibaba Cloud, activate OSS, and create a bucket space.
2. Demo (refer to https://github.com/sinkcup/Services_Aliyun_OSS/blob/0.0.1/tests/Services/Aliyun/OSSTest.php):
<?<span php </span><span require</span> Services/Aliyun/OSS.<span php; </span><span $conf</span> = <span array</span><span ( </span>'accessKeyId' => 'foo', 'accessKeySecret' => 'bar',<span ); </span><span $c</span> = <span new</span> Services_Aliyun_OSS('com-example-dl', <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>->put('/home/u1/2.jpg', '/2.jpg', <span $headers</span><span ); </span><span var_dump</span>(<span $r</span><span ); </span><span $this</span>->assertArrayHasKey('internet', <span $r</span><span ); </span>?>
Project code: https://github.com/sinkcup/Services_Aliyun_OSS
PEAR channel: http://sinkcup.github.io/pear/