composer安装文件下载
https://getcomposer.org/Composer-Setup.exe
composer安装:
选择php.exe
D:\phpStudy\php55n\php.exe
Compare
D:\phpStudy\php55n\php.ini
D:\phpStudy\php55n\php.ini~orig
++++
extension=php_openssl.dll
++++
查看composer版本
cmd
composer -V
Composer version 1.9.1 2019-11-01 17:20:17
设置composer
cmd
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer clear-cache
利用composer为项目syhuo.net安装第三方包oss-sdk-php
cd E:\telpo\syhuo.net\syhuo.net
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer clear-cache
发现composer.json被修改
M E:\telpo\syhuo.net\syhuo.net\composer.json
"repositories": {
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
}
composer require aliyuncs/oss-sdk-php
M E:\telpo\syhuo.net\syhuo.net\composer.json
"require" : {
"elasticsearch/elasticsearch": "~2.0",
"qcloud/cos-sdk-v5": ">=1.0",
"aliyuncs/oss-sdk-php": "^2.3"
},
M E:\telpo\syhuo.net\syhuo.net\composer.lock
M E:\telpo\syhuo.net\syhuo.net\vendor\autoload.php
M E:\telpo\syhuo.net\syhuo.net\vendor\composer\*
A E:\telpo\syhuo.net\syhuo.net\vendor\aliyuncs\*
封装aliyuncs/oss-sdk-php接口
[root@VM_58_118_centos syhuo.net]# vim General/Classes/AcloudApi.php
<?php
namespace General\Classes; /**
* Acloud 接口类
* @author 刘超 <[email protected]> 2019-12-05
*/
class AcloudApi
{
protected $config = [
'accessyeyid' => 'LTAI4Fm1GK7WAwgdkHgREBWT',
'accesskeysecret' => 'UxTwM4II0aWSFPhAPepcyDSM3iO9YJ',
'endpoint' => 'http://oss-accelerate.aliyuncs.com',
'bucket' => 'syhuo-1251970097',
];
protected $ossClient = null;
/**
* [__construct description]
* @author 刘超 <[email protected]> 2019-12-05
*/
public function __construct()
{
$ossClient = new \OSS\OssClient(
$this->config['accessyeyid'],
$this->config['accesskeysecret'],
$this->config['endpoint']
);
$this->ossClient = $ossClient;
}
/**
* [upload description]
* @author 刘超 <[email protected]> 2019-12-05
* @param string $keys [description]
* @param string $bodys [description]
* @return [type] [description]
*/
public function uploadfile($keys = '', $bodys = '')
{
try {
//Uploads a local file to an OSS file
$result = $this->ossClient->uploadFile(
$this->config['bucket'],
ltrim($keys,'/'),
$bodys
);
return $result;
} catch (\OSS\Core\OssException $e) {
print $e->getMessage();
} } /**
* [delete description]
* @author 刘超 <[email protected]> 2019-12-05
* @param [type] $key [description]
* @return [type] [description]
*/
public function delete($key)
{
// Delete an object
return $result = $this->ossClient->deleteObject(
$this->config['bucket'],
ltrim($key,'/')
);
}
}